Curl拒绝清除缓存的会话/ cookie

时间:2011-02-04 19:58:09

标签: php codeigniter curl

我在使用CURL而不清除其会话cookie的PHP页面时遇到问题。代码如下:

    $crl = curl_init();
    $timeout = 5;
    curl_setopt ($crl, CURLOPT_COOKIESESSION, 1);
    curl_setopt ($crl, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt ($crl, CURLOPT_URL,$url);
    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($crl, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($crl, CURLOPT_COOKIE, "");

    //curl_setopt($crl, CURLOPT_COOKIEFILE, 'cookies.txt');
    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
    $page = curl_exec($crl);
    curl_close($crl);

正如您所看到的,我已经尝试了几个功能来清除会话。我还注释掉了cookie文件。但是,当我启用cookiefile时,脚本仍会使用之前使用的相同cookie信息来重新检索页面。

有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:1)

尝试在$ url变量中附加时间戳:$ url。 '?t ='。时间()。

我通常会尝试使用cookiejar,我总是尝试设置两个选项:

curl_setopt($crl, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($crl, CURLOPT_COOKIEJAR, 'cookies.txt');

启用此功能时,cookies.txt是否可写?