【发布时间】:2012-09-28 19:38:48
【问题描述】:
我正在运行 EasyPHP 和 PHP5 的 Windows 7 机器上测试此代码 sn-p,当我运行代码时它仍然返回代码 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)
【问题讨论】:
-
我相信 cURL 可以选择禁用重定向。
-
当我调用一个“假”站点时,我个人将其解释为无效页面,在该站点您会收到错误页面,我将收到响应代码 404,并且不会被重定向。到目前为止,我看不出你的问题是什么......
-
你现在应该可以看到代码了,它只是和很多例子中的一样,所以我不知道为什么会出现这个问题。
-
我没有看到从
http://www.bnkbkvbirbcx.co.uk到http://www.123-reg.co.uk的任何重定向。 -
var_dump($hr, curl_getinfo($ch));在$hr = curl_exec($ch);之后。给我们输出。向您的 ISP 提出的所有问题。我什至找不到www.bnkbkvbirbcx.co.uk甚至bnkbkvbirbcx.co.uk的DNS 记录。看起来他们实现了一些重定向系统,该系统会自动为不存在的域提供 200 个答案。