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
)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章