复制代码 代码如下:
$url = ‘http://www.baidu.com';
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
if(false == $contents)
{
echo ‘Curl error: ‘ . curl_error($ch);
}
else
{
….
}
复制代码 代码如下:
curl_getinfo($ch, CURLINFO_HTTP_CODE);