在以下的代碼中我已經成功獲取了cookies並保存在txt文檔裡,但是無法跳轉到登錄頁面。請教?
<?php
$ch = curl_init();
$data='email= &password= &autologin=0';
$cookie_file=fopen($_SERVER['DOCUMENT_ROOT']."\cookies.txt","w");
curl_setopt($ch, CURLOPT_URL, "http://www.imooc.com/user/newlogin/from_url/1003");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_COOKIEJAR,$_SERVER['DOCUMENT_ROOT']."\cookies.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE,$_SERVER['DOCUMENT_ROOT']."\cookies.txt");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_exec($ch);
curl_setopt($ch,CURLOPT_URL,"http://www.imooc.com/space/index");
curl_setopt($ch,CURLOPT_POST,0);
$output=curl_exec($ch);
echo $output;
curl_close($ch);
?>
用fiddler調試下,看看是不是301/302跳轉有問題。