我正在运行 EasyPHP 和 PHP5 的 Windows 7 机器上测试此代码片段,当我运行代码时它仍然返回代码 200,我使用的是不存在的 url,所以它不应该,应该吗?这是因为重定向发生在例如http://www.123-reg.co.uk吗?这就是我的怀疑,但我正在努力寻找如何解决这个问题。
$url = "http://www.bnkbkvbirbcx.co.uk";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
$hr = curl_exec($ch);
$httpreturncode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $httpreturncode;
插入 var_dump($hr, curl_getinfo($ch)) 会产生这个输出;
string 'HTTP/1.1 200 OK
Date: Fri, 28 Sep 2012 20:18:16 GMT
Server: Apache
Cache-control: no-cache, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=UTF-8
' (length=224)
array
'url' => string 'http://www.bnkbkvbirbcx.co.uk' (length=29)
'content_type' => string 'text/html; charset=UTF-8' (length=24)
'http_code' => int 200
'header_size' => int 224
'request_size' => int 62
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.063
'namelookup_time' => float 0.016
'connect_time' => float 0.031
'pretransfer_time' => float 0.031
'size_upload' => float 0
'size_download' => float 0
'speed_download' => float 0
'speed_upload' => float 0
'download_content_length' => float -1
'upload_content_length' => float 0
'starttransfer_time' => float 0.063
'redirect_time' => float 0
'certinfo' =>
array
empty
'redirect_url' => string '' (length=0)