php获取某个请求链接的head内容

php的get_headers可以取得服务器响应一个 HTTP 请求所发送的所有标头。

$url = 'http://www.baidu.com';
print_r(get_headers($url));

返回结果打印:

Array
(
    [0] => HTTP/1.0 200 OK
    [1] => Accept-Ranges: bytes
    [2] => Cache-Control: no-cache
    [3] => Content-Length: 14615
    [4] => Content-Type: text/html
    [5] => Date: Thu, 04 Jun 2020 02:20:26 GMT
    [6] => P3p: CP=" OTI DSP COR IVA OUR IND COM "
    [7] => P3p: CP=" OTI DSP COR IVA OUR IND COM "
    [8] => Pragma: no-cache
    [9] => Server: BWS/1.1
    [10] => Set-Cookie: BAIDUID=E06891B4DB45438CD747DE2C727E3A4C:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [11] => Set-Cookie: BIDUPSID=E06891B4DB45438CD747DE2C727E3A4C; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [12] => Set-Cookie: PSTM=1591237226; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [13] => Set-Cookie: BAIDUID=E06891B4DB45438CF2A69A5B7E76C5D5:FG=1; max-age=31536000; expires=Fri, 04-Jun-21 02:20:26 GMT; domain=.baidu.com; path=/; version=1; comment=bd
    [14] => Traceid: 159123722603713328747731731840894872658
    [15] => Vary: Accept-Encoding
    [16] => X-Ua-Compatible: IE=Edge,chrome=1
)

 

你可能感兴趣的:(php学习笔记)