我想你应该在你的 CURL 请求中设置 cookie
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://blog.yousoft.ru/');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE,$cookie);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Bot (http://blog.yousoft.ru)');
$data = curl_exec($ch);
$header=substr($data,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
$body=substr($data,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
preg_match_all("/Set-Cookie: (.*?)=(.*?);/i",$header,$res);
$cookie='';
foreach ($res[1] as $key => $value) {
$cookie.= $value.'='.$res[2][$key].'; ';
};
curl_close($ch);
或者
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://blog.yousoft.ru/');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Bot (http://blog.yousoft.ru)');
$data = curl_exec($ch);
curl_close($ch);
参考(俄语):http ://blog.yousoft.ru/2010/03/31/ispolzuem-curl-php-chast-4-rabotaem-s-cookies-2-sposoba/