【问题标题】:status of php, curl sessionphp 状态,curl 会话
【发布时间】:2012-06-23 08:51:54
【问题描述】:

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

【问题讨论】:

    标签: php session cookies curl


    【解决方案1】:

    您需要获取 cookie 并在下一个请求中使用它们,例如:

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

    【讨论】:

    • 你说他们是什么意思。其次,我将如何知道该会话是生是死。所以我可以知道,我是否需要重新连接。
    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 2019-10-28
    相关资源
    最近更新 更多