php下获取http状态的实现代码
程序员文章站
2023-11-26 14:11:16
逐风整理了两种方式,大家可以自行参考/使用:
复制代码 代码如下:#方式一$ch = curl_init('//www.jb51.net');curl_setopt($...
逐风整理了两种方式,大家可以自行参考/使用:
复制代码 代码如下:
#方式一
$ch = curl_init('//www.jb51.net');
curl_setopt($ch, curlopt_returntransfer, 1);
curl_exec($ch);
echo curl_getinfo($ch, curlinfo_http_code); // 200
curl_close($ch);
方式二
复制代码 代码如下:
print_r(
get_headers('http://www.baidu.com')
);
#返回以下内容:
/*
array
(
[0] => http/1.1 200 ok
[1] => date: sun, 04 may 2014 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] => expires: sun, 04 may 2014 03:42:09 gmt
[11] => x-powered-by: hphp
[12] => server: bws/1.1
[13] => bdpagetype: 1
[14] => bdqid: 0x9acb602d00001922
[15] => bduserid: 0
)
*/
上一篇: python求素数示例分享
下一篇: Python中自定义函数的教程