PHP获取HTTP头信息

  • 获取全部(客户端)HTTP请求头信息
    #1
    array apache_request_headers(void)

    #2:通过$_SERVER获取,每个http请求头信息都以"HTTP_"开头在$_SERVER键中
    # 获取if_modified_since的请求信息
    $_SERVER['HTTP_IF_MODIFIED_SINCE']
  • 获取服务器响应一个HTTP请求所发送的所有标头
    # url 请求的服务器的URL地址
    # format 0:返回的头部信息以索引数字形式,1:返回头部信息以关联数组形式
    array get_headers(string $url [, int $format = 0 ] )

    #示例
    $head_arr = get_headers("https://www.baidu.com");
    $head_arr_index = get_headers("https://www.baidu.com",1);
    echo "<pre>";
        print_r($head_arr);
        print_r($head_arr_index);
    echo "</pre>";
    #输出结果分别为:
    #head_arr
    Array
    (
        [0] => HTTP/1.1 200 OK
        [1] => Server: bfe/1.0.8.18
        [2] => Date: Tue, 25 Apr 2017 02:50:57 GMT
        [3] => Content-Type: text/html
        [4] => Content-Length: 14720
        [5] => Connection: close
        [6] => Last-Modified: Tue, 18 Apr 2017 01:09:00 GMT
        [7] => Vary: Accept-Encoding
        [8] => Set-Cookie: BAIDUID=B4D4AA198C8E598CF3980583DA807FA1:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
        [9] => Set-Cookie: BIDUPSID=B4D4AA198C8E598CF3980583DA807FA1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
        [10] => Set-Cookie: PSTM=1493088657; 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=12770957019260228058_00_10_N_N_15_0303_C02F_N_N_N_0; expires=Tue, 25-Apr-17 02:51:02 GMT; domain=www.baidu.com; path=/
    )


    #head_arr_index
    Array
    (
        [0] => HTTP/1.1 200 OK
        [Server] => bfe/1.0.8.18
        [Date] => Tue, 25 Apr 2017 02:47:11 GMT
        [Content-Type] => text/html
        [Content-Length] => 14720
        [Connection] => close
        [Last-Modified] => Tue, 18 Apr 2017 01:09:00 GMT
        [Vary] => Accept-Encoding
        [Set-Cookie] => Array
            (
                [0] => BAIDUID=D0D69F175CC2E4C205E8EA6D1DEAA1BB:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
                [1] => BIDUPSID=D0D69F175CC2E4C205E8EA6D1DEAA1BB; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
                [2] => PSTM=1493088431; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
                [3] => __bsi=11987508469614704611_00_22_N_N_16_0303_C02F_N_N_N_0; expires=Tue, 25-Apr-17 02:47:16 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
    )
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值