How PHP gets the HTTP status
In the project development, sometimes we need to know whether the remote URL address can be accessed properly, to determine its normal or not after the next operation, then in PHP How to get the status of remote HTTP?
Wind up two ways, we can refer to the use of:
#方式一 $ch = curl_init (' http://www.scutephp.com '); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_exec ($ch); Echo Curl _getinfo ($ch, Curlinfo_http_code); 200curl_close ($ch);
#方式二print_r (get_headers (' http://www.baidu.com ')); #返回以下内容:/*array ( [0] = http/1.1-OK [1] = = Date:sun, 03:43:04 GMT [2] = content-type:text/html; Charset=utf-8 [3] = connection:close
[4] = vary:accept-encoding [5] = set-cookie:baiduid=4977af4fb1e9a5d13c79939e28d92161:fg=1; expires= Thu, 31-dec-37 23:55:55 GMT; max-age=2147483647; path=/; Domain=.baidu.com [6] = set-cookie:bdsvrtm=0; path=/ [7] = set-cookie:h_ps_pssid=4681_1465_5224_ 6023_4759_6018_6257_6313_6328_6269; path=/; Domain=.baidu.com [8] = p3p:cp= "OTI DSP COR IVA our IND com" [9] = = Cache-control:private [10] =& Gt Expires:sun, 03:42:09 GMT [one] and x-powered-by:hphp [[] = server:bws/1.1 [] = Bdpagetype:1 [+] = bdqid:0x9acb602d00001922 [[] = bduserid:0 ) */