我試圖將以下代碼發送到登錄表單,然後在瀏覽器中以登錄用戶身份重新加載該頁面。不知何故,它不保存cookie,並重新使用它的頭()函數,可以通過發送登錄細節後再次調用curl來完成與頭相同的事情?通過curl登錄,然後打開該頁面登錄
..
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , false);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
// Apply the XML to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch);
setcookie($cookie);
header('location: ' . $url);
die();
這是爲同一個域?如果不是那麼它不可能。如果是的話,我就是不明白。此外,沒有理由死在最後。 – zaf 2010-04-06 18:16:09