file_get_contents获取状态码

<?php

//加上@ 是为了防止file_get_contents获取失败返回至命错误,影响后面的程序运行

@file_get_contents("http://tqybw.net");
var_dump($http_response_header);
//$http_response_header 数组与 get_headers() 函数类似。当使用HTTP 包装器时,$http_response_header 将会被 HTTP 响应头信息填充。
//$http_response_header 将被创建于局部作用域中。

?>

//输出结果

array(16) {
  [0]=>
  string(15) "HTTP/1.0 200 OK"
  [1]=>
  string(20) "Accept-Ranges: bytes"
  [2]=>
  string(23) "Cache-Control: no-cache"
  [3]=>
  string(21) "Content-Length: 14722"
  [4]=>
  string(23) "Content-Type: text/html"
  [5]=>
  string(35) "Date: Wed, 28 Nov 2018 06:11:27 GMT"
  [6]=>
  string(21) "Etag: "5bf3770c-3982""
  [7]=>
  string(44) "Last-Modified: Tue, 20 Nov 2018 02:53:00 GMT"
  [8]=>
  string(39) "P3p: CP=" OTI DSP COR IVA OUR IND COM ""
  [9]=>
  string(16) "Pragma: no-cache"
  [10]=>
  string(15) "Server: BWS/1.1"
  [11]=>
  string(141) "Set-Cookie: BAIDUID=9F2F8D69F1017368E0269BCAE89CF63A:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com"
  [12]=>
  string(137) "Set-Cookie: BIDUPSID=9F2F8D69F1017368E0269BCAE89CF63A; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com"
  [13]=>
  string(111) "Set-Cookie: PSTM=1543385487; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com"
  [14]=>
  string(21) "Vary: Accept-Encoding"
  [15]=>
  string(33) "X-Ua-Compatible: IE=Edge,chrome=1"
}

 


posted @ 2018-11-28 14:14  进阶丶xiao路  阅读(2234)  评论(0编辑  收藏  举报