note 78625 rejected from ref.session by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:05:03 +0000 |
| Subject: | note 78625 rejected from ref.session by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134340@lists.php.net to get a copy of this message | ||
Note Submitter: mikeh at view22 dot com
----
Observed what I think is a bug: session cookies were expiring even though the session was still
active. (To test, set a cookie expiry of 5 seconds and keep hitting the page every second. The
session will expire and create a new SESSID after 5 seconds despite the fact that you hit the page
only a second ago.)
Calling this function before starting the session fixed it. It copies the cookie contents back to
itself while forcing an update to the expiry time in the cookie.
function FreshenSessionCookie($lifetimeSeconds, $cookieName = 'PHPSESSID')
{
if (isset($_COOKIE[$cookieName]))
{
$data = $_COOKIE[$cookieName];
$timeout = time()+$lifetimeSeconds;
setcookie($cookieName, $data, $timeout);
}
}