PHP get_headers函数的介绍

Posted DC Technology Stack

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP get_headers函数的介绍相关的知识,希望对你有一定的参考价值。

php 文档中关于get_headers函数的介绍:

(PHP 5, PHP 7)

get_headers — 取得服务器响应一个 HTTP 请求所发送的所有标头
$url = "https://www.baidu.com";
$response = get_headers($url);
echo "<pre>";
print_r($response);
$response = get_headers($url,1);
echo ‘<pre>‘;
print_r($response);

结果:

  

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Server: bfe/1.0.8.18
    [2] => Date: Wed, 29 Mar 2017 03:59:26 GMT
    [3] => Content-Type: text/html
    [4] => Content-Length: 14720
    [5] => Connection: close
    [6] => Last-Modified: Tue, 14 Mar 2017 07:30:00 GMT
    [7] => Vary: Accept-Encoding
    [8] => Set-Cookie: BAIDUID=A674E52FA6AF0193F9CDEE45C7A59821:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [9] => Set-Cookie: BIDUPSID=A674E52FA6AF0193F9CDEE45C7A59821; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [10] => Set-Cookie: PSTM=1490759966; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [11] => P3P: CP=" OTI DSP COR IVA OUR IND COM "
    [12] => X-UA-Compatible: IE=Edge,chrome=1
    [13] => Pragma: no-cache
    [14] => Cache-control: no-cache
    [15] => Accept-Ranges: bytes
    [16] => Set-Cookie: __bsi=18181989014312142897_00_998_N_N_8_0303_C02F_N_N_N_0; expires=Wed, 29-Mar-17 03:59:31 GMT; domain=www.baidu.com; path=/
)
Array
(
    [0] => HTTP/1.1 200 OK
    [Server] => bfe/1.0.8.18
    [Date] => Wed, 29 Mar 2017 03:59:26 GMT
    [Content-Type] => text/html
    [Content-Length] => 14720
    [Connection] => close
    [Last-Modified] => Tue, 14 Mar 2017 07:30:00 GMT
    [Vary] => Accept-Encoding
    [Set-Cookie] => Array
        (
            [0] => BAIDUID=A674E52FA6AF0193A9330C0C2F20BED6:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [1] => BIDUPSID=A674E52FA6AF0193A9330C0C2F20BED6; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [2] => PSTM=1490759966; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [3] => __bsi=16875695485765166328_00_13_N_N_8_0303_C02F_N_N_N_0; expires=Wed, 29-Mar-17 03:59:31 GMT; domain=www.baidu.com; path=/
        )

    [P3P] => CP=" OTI DSP COR IVA OUR IND COM "
    [X-UA-Compatible] => IE=Edge,chrome=1
    [Pragma] => no-cache
    [Cache-control] => no-cache
    [Accept-Ranges] => bytes
)

  服务器是否能够正常访问,可以使用这个函数来判断

 

以上是关于PHP get_headers函数的介绍的主要内容,如果未能解决你的问题,请参考以下文章

PHP利用get_headers()函数判断远程的url地址是否有效

PHP curl函数制 exec_ch和get_headers

PHP获取重定向URL的几种方法

致命错误:在第 2 行的 index.php 中调用未定义函数 get_header()

在网页上包含外部代码( php include() 或 get_header() )

PHP中的URL处理