2012-06-21 58 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