Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP https://


แนะนำตัว

https:// และ https:// wrappers เปิดใช้งานการเข้าถึงทรัพยากรและไฟล์แบบอ่านอย่างเดียวผ่านโปรโตคอล HTTP เมื่อจัดการโฮสต์ตามชื่อเสมือน โฮสต์: ส่วนหัวก็ส่งไปพร้อมกับ user_agent (หากกำหนดค่าใน php.ini)

ข้อมูลส่วนหัว http ถูกเก็บไว้ใน $http_response_header ตัวแปร. ส่วนหัวเหล่านี้ต้องได้รับการประมวลผลจึงจะทราบ URL ของทรัพยากรที่เอกสารมาจากโดยใช้จาก: ส่วนหัว

รองรับ HTTPS เฉพาะเมื่อ openssl ส่วนขยายถูกเปิดใช้งานในการตั้งค่า php.ini การเชื่อมต่อทั้ง HTTP และ HTTPS เป็นแบบอ่านอย่างเดียวและไม่รองรับการเขียนหรือคัดลอกไฟล์

การใช้งาน

การแสดงชื่อไฟล์ในรูปแบบต่างๆ มีดังนี้ -

https://localhost
https://example.com
https://localhost?name='Ram'&age=20
https://example.com
https://username:password@abc.com

ตัวอย่าง

<?php
$url = 'https://www.tutorialspoint.com/php7/php7_closure_call.htm';
if (!$fp = fopen($url, 'r')) {
   trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$meta = stream_get_meta_data($fp);
print_r($meta);
?>

สคริปต์ด้านบนอ่านข้อมูลเมตาของส่วนหัวจาก http URL

Array(
   [crypto] => Array(
      [protocol] => TLSv1.2
      [cipher_name] => ECDHE-RSA-AES128-GCM-SHA256
      [cipher_bits] => 128
      [cipher_version] => TLSv1/SSLv3
   )

   [timed_out] =>
   [blocked] => 1
   [eof] =>
   [wrapper_data] => Array(
      [0] => HTTP/1.0 200 OK
      [1] => Age: 1310067
      [2] => Cache-Control: max-age=2592000
      [3] => Content-Type: text/html; charset=UTF-8
      [4] => Date: Mon, 14 Sep 2020 17:15:36 GMT
      [5] => Expires: Wed, 14 Oct 2020 17:15:36 GMT
      [6] => Last-Modified: Sun, 30 Aug 2020 13:21:09 GMT
      [7] => Server: ECS (nag/99AA)
      [8] => Strict-Transport-Security: max-age=63072000; includeSubdomains
      [9] => Vary: Accept-Encoding
      [10] => X-Cache: HIT
      [11] => X-Content-Type-Options: nosniff
      [12] => X-Frame-Options: SAMEORIGIN
      [13] => X-XSS-Protection: 1; mode=block
      [14] => Content-Length: 24102
      [15] => Connection: close
   )
   [wrapper_type] => http
   [stream_type] => tcp_socket/ssl
   [mode] => r
   [unread_bytes] => 0
   [seekable] =>
   [uri] => https://www.tutorialspoint.com/php7/php7_closure_call.htm
)