PHP get_headers()函数详解
程序员文章站
2022-03-25 17:01:14
get_headers,获取服务器发送给http请求的所有头信息 ......
定义
get_headers - 取得服务器响应一个 http 请求所发送的所有头信息
描述
get_headers ( string $url [, int $format = 0 [, resource $context ]] ) : array
如果将 format 参数设为 1,则 get_headers() 返回带键值的关联数组。
context 参数
a valid context resource created with stream_context_create().
示例
<?php $url = 'http://www.example.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); ?>
输出
array ( [0] => http/1.1 200 ok [1] => date: sat, 29 may 2004 12:28:13 gmt [2] => server: apache/1.3.27 (unix) (red-hat/linux) [3] => last-modified: wed, 08 jan 2003 23:11:55 gmt [4] => etag: "3f80f-1b6-3e1cb03b" [5] => accept-ranges: bytes [6] => content-length: 438 [7] => connection: close [8] => content-type: text/html ) array ( [0] => http/1.1 200 ok [date] => sat, 29 may 2004 12:28:14 gmt [server] => apache/1.3.27 (unix) (red-hat/linux) [last-modified] => wed, 08 jan 2003 23:11:55 gmt [etag] => "3f80f-1b6-3e1cb03b" [accept-ranges] => bytes [content-length] => 438 [connection] => close [content-type] => text/html )
上一篇: 只需一台电脑,人人都可用 Python 实现新冠病毒分布实时追踪
下一篇: 数据结构-线性表