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

PHP http:// Wrapper

บทนำ

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

ข้อมูล HTTP header จะถูกเก็บในตัวแปร $http_response_header ต้องประมวลผล header เหล่านี้เพื่อทราบ URL ของทรัพยากรที่เอกสารมาจากด้วยความช่วยเหลือของ header from:

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

การใช้งาน

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

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); ?>

สคริปต์ข้างต้นอ่าน header metadata จาก 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 )