大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这期内容当中小编将会给大家带来有关如何在php中使用curl获取header检测,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联于2013年成立,是专业互联网技术服务公司,拥有项目成都做网站、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元朔城做网站,已为上家服务,为朔城各地企业和个人服务,联系电话:13518219792方法一:使用get_headers()
函数
这个方法很多人使用,也很简单便捷,只需要两行代码即可搞定。如下:
$thisurl = "/tupian/20230522/"; 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 = "/tupian/20230522/"; $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 = "/tupian/20230522/"; $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"
[4] => Server: Microsoft-IIS/7.5
[5] => X-Powered-By: jb51.net
[6] => Date: Wed, 15 Aug 2018 01:39:35 GMT
[7] => Connection: close
[8] => Content-Length: 89421
)
[wrapper_type] => http
[stream_type] => tcp_socket/ssl
[mode] => r
[unread_bytes] => 7945
[seekable] =>
[uri] => /tupian/20230522/ [timed_out] =>
[blocked] => 1
[eof] =>
)
上述三种方法都可以轻松获得网页header信息,且包含的信息都已经相当丰富,满足一般要求,不过比较遗憾的是,上述三种方法都不能用来检测网页是否启用了GZip压缩。要检测GZip压缩,还需其他的方法才行。这里介绍的是用curl()
函数来检测。
先贴出代码:
', $pHeader); //使用
换行符格式化输出到网页上 echo $pHeader; } ?>
输出结果如下:
HTTP/1.1 200 OK
Cache-Control: max-age=86400
Content-Length: 15189
Content-Type: text/html
Content-Encoding: gzip
Content-Location: http://www.webkaka.com/index.html
Last-Modified: Fri, 19 Jul 2013 03:52:28 GMT
Accept-Ranges: bytes
ETag: "0268633384ce1:5cb3"
Vary: Accept-Encoding
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Fri, 19 Jul 2013 09:27:21 GMT
上述就是小编为大家分享的如何在php中使用curl获取header检测了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。