I just come to do some test this afternoon and here are the results.

<page_1.php>
<?php
session_start();
$bar = 'hello';
$now = date('H:i:s');
$_SESSION['foo'] = $bar;
$_SESSION['begin'] = $now;
header('Location: page_2.php?'.SID);
exit;
?>

<page_2.php>
<?php
session_start();
print_r($_SESSION);
echo '<br>Now : '.date('H:i:s');
?>
<a href="page_2.php?<?php echo SID; ?>">Reload</a>

And here are the results :
<Config>
session.use_cookie = 0;
session.gc_maxlifetime = 30; // 30 seconds
session.gc_probability = 100; // 100% => the gc is always called

On page 2, I have :
Array ( [begin] => 16:34:22, [foo] => hello )
Now : xx:xx:xx

I have this at the beginning and when I reload the page with the link, these information are the same (only => "Now : xx:xx:xx" changes as expected).
But after a little bit more that 30 seconds (never exactly 30 seconds) the gc is called and I have :
Array ()
Now : xx:xx:xx


And I do the same test with this config :
<Config>
session.use_cookie = 0;
session.gc_maxlifetime = 1440; // 24 minutes
session.gc_probability = 1; // 1% => the gc is called 1 time on 100

And here at the beginning all is correct, I refresh the page 2 every 15 minutes and here, the session is destroyed randomly after 1h20, 1h50...

So it seems that the lifetime on a cookie_less session is determined by the gc.max_lifetime.

Thanks for your help


Raquel Rice wrote:



In my sessions I set an "expire time", which is the current time (unix timestamp) plus the number of seconds I want a session to last. Each new page examines the current timestamp against the expire time. If the current time is less than the expire time, then the expire time is advanced again. Otherwise, the session is wiped out and the user sent to an error page. ========

$defExpireTime = 3600;
if ($_SESSION['expire'] <= (time() + $this->defExpireTime) {
    $_SESSION['expire'] = time() + $this->defExpireTime;
    # go ahead with session
} else {
    $_SESSION = array();
    # send the user to an error page
}

--

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to