这是我的 cUrl 代码,
function curl_cookieset() {
$fp = fopen("cookie.txt", "w");
fclose($fp);
/*visit the homepage to set the cookie properly */
$ch = curl_init ("http://www.autoscout24.de/ListGN.aspx?vis=1&state=A&atype=C&cy=D&page=1&results=20&ustate=N,U&sort=price&rfde=True&custtype=P&zipc=D");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101");
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec ($ch);
}
function curl_download($Url ){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
这就是我使用它的方式,
curl_cookieset();
while(true) {
//some other process
$result = curl_download($url);
//some other process
}
这可以在本地主机上正常工作,但是当我尝试在外部服务器上运行时,它没有设置 cookie,我也没有得到相同的结果。
注意:它创建 cookie.txt
cookie.txt chmod = 666
应该是什么问题?