繁体   English   中英

php的状态,curl会话

[英]status of php, curl session

我将使用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);

您需要获取Cookie并在下一个请求中使用'em,例如:

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); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM