PHP http://
phpserver side programmingprogramming
简介
http:// 和 https:// 封装器允许通过 HTTP 协议对资源和文件进行只读访问。处理基于虚拟名称的主机时,host: 标头也会与
http 标头信息存储在 变量中。必须处理这些标头,才能借助
仅在 php.ini 设置中启用
用法
文件名的不同表示方式如下 −
http://localhost http://example.com http://localhost?name='Ram'&age=20 https://example.com http://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 )