note 100674 deleted from function.session-set-cookie-params by danbrown
| From: | danbrown@php.net | Date: | Fri, 29 Oct 2010 11:41:08 +0000 |
| Subject: | note 100674 deleted from function.session-set-cookie-params by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173596@lists.php.net to get a copy of this message | ||
Note Submitter: Frank
----
@ final dot wharf at gmail dot com
You are changing the lifetime of the session cookie but not of the session. It may be still valid,
even if the session cookie expires.
In order to change the lifetime of the session you could use session.gc_maxlifetime. By default, the
gargabe collector isn't started on every page refresh. So there is one option left to handle
the session lifetime: create your own session lifetime management.
For example, initialize the session with the following vars
<?php
$_SESSION['start'] = time();
$_SESSION['end'] = time() + 1800;
?>
Then you create a simple routine, which you call at the beginning of your site, to extend the
session lifetime or to end the session:
<?php
if ($_SESSION['end'] < time()) {
session_unset();
session_destroy();
return;
}
if (($_SESSION['end'] - time()) > 0) {
return $_SESSION['end'] = time() + 1800;
}
?>