使用curl和file_get_contents 都无法取得源代码。使用 file_get_contents 提示的错误提示:Redirection limit reached, aborting
failed to open stream$url='http://s.etao.com/search?q=csdn&t=10&source=dg';
$content=curl_file_get_contents($url);
echo $content;$content2=file_get_contents($url);
echo $content2;function curl_file_get_contents($durl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $durl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
failed to open stream$url='http://s.etao.com/search?q=csdn&t=10&source=dg';
$content=curl_file_get_contents($url);
echo $content;$content2=file_get_contents($url);
echo $content2;function curl_file_get_contents($durl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $durl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
$url='http://s.etao.com/search?q=csdn&t=10&source=dg';
$content=curl_file_get_contents($url);
echo $content;
function curl_file_get_contents($durl){
$cookie_file = dirname(__FILE__)."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $durl);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
提示错误 Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in E:\html\baidu\test.php on line 14
修改你的php模式,不要运行在安全模式下即可!