我正在尝试使用cURL访问网页,我需要保存相关的Cookie。该代码仅适用于某些页面。是因为cookie是用cookie写的,不能保存在cookie上的页面上吗?这是我的代码:
function httpGet($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_MAXREDIRS,2);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
echo httpGet("http://www.aol.com/"); //Saves cookies to cookie.txt
echo httpGet("http://www.supremenewyork.com/"); //Does not save cookies
如何将Cookie保存在此页面上?谢谢。
答案 0 :(得分:0)
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
尝试在卷曲时添加referer到该URL