整理了两种方式,大家可以自行参考/使用:方式一$ch = curl_init('http://www.jb51.net');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE); // 200
curl_close($ch);
方式二var_dump( get_headers( $url ) );die;array (size=11)
0 => string 'HTTP/1.1 200 OK' (length=15)
1 => string 'Date: Fri, 18 Sep 2015 13:19:49 GMT' (length=35)
2 => string 'Server: Apache' (length=14)
3 => string 'Set-Cookie: PHPSESSID=rq1m0j8q1pherqt5je9pkocfn3; path=/' (length=56)
4 => string 'Expires: Thu, 19 Nov 1981 08:52:00 GMT' (length=38)
5 => string 'Cache-Control: private' (length=22)
6 => string 'Pragma: no-cache' (length=16)
7 => string 'X-Powered-By: ThinkPHP' (length=22)
8 => string 'Set-Cookie: safedog-flow-item=616104C9D9913E8608C9D0A4901EEA8B; expires=Mon, 25-Oct-2151 16:31:05 GMT; domain=php90.cn; path=/' (length=126)
9 => string 'Connection: close' (length=17)
10 => string 'Content-Type: text/html; charset=utf-8' (length=38)