1. 程式人生 > >file_get_contents獲取狀態碼

file_get_contents獲取狀態碼

ons domain 狀態 -a resp byte mod path -c

<?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" }


file_get_contents獲取狀態碼