0

下面的函数返回的结果与我们直接渲染页面的实际结果不同。

会是什么问题?

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;
}
4

1 回答 1

1

My guess is that your accessing it with one browser, but your setting the $useragent to another. The external site might be returning different data depending on the useragent

于 2012-05-08T23:54:06.507 回答