以下代码有什么问题?
<?php
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$var = file_get_contents_curl("http://www.sahibinden.com/131521670");
var_dump($var);
?>
它只显示bool(false)
将http://www.sahibinden.com/131521670放在浏览器地址栏上时,网址可能会出现问题,浏览器会重定向到我想要其内容的其他网页。
当我添加以下行
时curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp );
输出
* About to connect() to www.sahibinden.com port 80 (#0)
* Trying 195.33.232.72... * connected
* Connected to www.sahibinden.com (195.33.232.72) port 80 (#0)
> GET /131521670 HTTP/1.1
Host: www.sahibinden.com
Accept: */*
* Closing connection #0
* Failure when receiving data from the peer
CURLOPT_HEADER,1);也产生相同的结果。