2012-06-21 95 views
0

我打算使用curl登錄一個網站。它的登錄狀態良好。現在我想知道會話的狀態,它是否存在。因爲用戶可以在登錄後發送不同頁面的請求。我的代碼在這裏。感謝php的狀態,curl會話

$url="https://mywebsite.com/login.pl"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=xxxxxx&passwd=xxxxx&client=xxxxx"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_MAXREDIRS, 4); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$store = curl_exec ($ch); 
curl_close ($ch); 

回答

0

你需要搶餅乾和使用'時間在你的下一個請求,是這樣的:

curl_setopt($ch, CURLOPT_COOKIE,   $cookie); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
curl_setopt($ch, CURLOPT_FAILONERROR, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
curl_setopt($ch, CURLOPT_HEADER,   false); 
curl_setopt($ch, CURLOPT_POST,   false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
curl_close($ch); 
+0

是什麼你的意思他們。其次,我將如何知道該會議還活着或已經死亡。所以我可以知道,我需要重新連接還是不需要。 – nbhatti2001