Php cURL返回不同的结果

Php cURL返回不同的结果,php,curl,Php,Curl,下面的函数返回的结果与我们直接呈现页面的结果不同 问题是什么 function file_get_contents_curl($url) { $ch = curl_init(); $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)Gecko/20061204 Firefox/2.0.0.1"; curl_setopt($ch, CURLOPT_HEADER, 0); cur

下面的函数返回的结果与我们直接呈现页面的结果不同

问题是什么

function file_get_contents_curl($url) {
    $ch = curl_init();
    $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)Gecko/20061204 Firefox/2.0.0.1";
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    curl_close($ch);

return $data;
}

我的猜测是,您使用一个浏览器访问它,但将
$useragent
设置为另一个浏览器。外部站点可能会返回不同的数据,具体取决于用户代理

您在直接访问它时使用的浏览器?是否有任何方法可以获取不依赖于用户代理的外部站点内容?当然,只是不要使用
$useragent
。问题仍然存在。我试图通过这个来获得谷歌搜索结果。它给出了一个不同的计数和输出,比如“200000个结果”,这与最初的“500000个结果”不同。哦,那就不同了。如果你试图通过cURL访问谷歌,你会遇到问题。众所周知,当他们认为有人试图窃取他们的服务时,他们会返回虚假数据。不管怎么说,谷歌违反了他们的TOS。。。第5.3节