2012-10-17 20 views
2

我無法弄清楚爲什麼這個URL沒有被CURL找到。 CURL引擎僅被帶到400錯誤頁面。php CURL不能使用動態網址

我的代碼非常簡單,並且非常動態地使用網址。

我希望能夠很容易發現,例如,缺少CURL選項。

我已經嘗試使用$ url = urlencode($ url),但那也不管用。

下面的代碼:

$url = 'http://www.destinations-uk.com/accommodations.php?link=accommodations&country=england&category=Reviews&id=1'; 
$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_CONNECTTIMEOUT, 2); 
curl_setopt($ch, CURLOPT_TIMEOUT,  15); 
$r = curl_exec($ch); 
$r = explode("\n", $r); 
$keys = array(); 
if(!empty($r)) $keys[] = array_shift($r); 
foreach($r as $line){ 
    preg_match('/.+:\s/',$line,$match); 
    if($match) $keys[substr($match[0],0,-2)] = preg_replace('/.+:\s/','', $line); 
} 
print_r($keys); 

回答

0

也許,這是爲了防止自動請求服務器端的東西。

+0

我認爲你一定是對的 - 它適用於基於谷歌的動態URL。謝謝! – whizzkid