2013-04-10 98 views
1

我已經編寫了這段代碼來獲取來自谷歌的所有數據,但它返回空白。代碼是CURL返回空白頁

$page = "http://www.google.com"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $page); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$contents = curl_exec ($ch); 
curl_close ($ch); 
echo $contents; 

任何人都可以找到這個代碼有什麼問題嗎? 我檢查php信息我的捲曲已啓用。

+3

試試[http://php.net/ manual/en/function.curl-error.php](http://php.net/manual/en/function.curl-error.php) – machineaddict 2013-04-10 13:26:25

+0

你有一個*** PHP解析錯誤:語法錯誤,意外結束文件,期待在你的代碼中的***。修復它顯示它工作正常:http://codepad.viper-7.com/9Yxr7h – 2013-04-10 13:29:09

+0

嘗試[PHP CURL無返回](http://stackoverflow.com/questions/6324819/php-curl-returns-nothing) – 2013-04-10 13:29:56

回答

0

在我的情況下谷歌的HTTP服務器的回答包含一個重定向到http://www.google.ru/

HTTP/1.1 302 Found 
Location: http://www.google.ru/ 

讓嫋嫋遵循這個 「位置:」 頭:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);