首页 > 开发 > PHP > 正文

php使用curl获取header检测开启GZip压缩的方法

2024-05-04 22:42:24
字体:
来源:转载
供稿:网友

本文实例讲述了php使用curl获取header检测开启GZip压缩的方法。分享给大家供大家参考,具体如下:

获得网页header信息,是网站开发人员和维护人员常用的技术。网页的header信息,非常丰富,非专业人士一般较难读懂和理解各个项目的含义。

获取网页header信息,方法多种多样,就php语言来说,我作为一个菜鸟,知道的方法也有4种那么多。下面逐一献上。

方法一:使用get_headers()函数

这个方法很多人使用,也很简单便捷,只需要两行代码即可搞定。如下:

$thisurl = "https://www.jb51.net/";print_r(get_headers($thisurl, 1));

得到的结果为:

Array
(
    [0] => HTTP/1.1 200 OK
    [Content-Type] => text/html
    [Last-Modified] => Wed, 15 Aug 2018 01:23:03 GMT
    [ETag] => "99a921833634d41:0"
    [Server] => Microsoft-IIS/7.5
    [X-Powered-By] => jb51.net
    [Date] => Wed, 15 Aug 2018 01:31:48 GMT
    [Connection] => close
    [Content-Length] => 89251
)

方法二:使用http_response_header

代码也很简单,仅需三行:

$thisurl = "https://www.jb51.net/";$html = file_get_contents($thisurl ); print_r($http_response_header);

得到的结果为:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Content-Type: text/html
    [2] => Last-Modified: Wed, 15 Aug 2018 01:33:04 GMT
    [3] => ETag: "7b9757e93734d41:0"
    [4] => Server: Microsoft-IIS/7.5
    [5] => X-Powered-By: jb51.net
    [6] => Date: Wed, 15 Aug 2018 01:34:15 GMT
    [7] => Connection: close
    [8] => Content-Length: 89282
)

方法三:使用stream_get_meta_data()函数

代码也只有三行:

$thisurl = "https://www.jb51.net/";$fp = fopen($thisurl, 'r'); print_r(stream_get_meta_data($fp));

得到的结果为:

Array
(
    [wrapper_data] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Content-Type: text/html
            [2] => Last-Modified: Wed, 15 Aug 2018 01:38:45 GMT
            [3] => ETag: "ecc8f8b43834d41:0"

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表