note 78624 deleted from function.setcookie by cmb

From: Date: Sun, 03 Mar 2019 11:29:02 +0000
Subject: note 78624 deleted from function.setcookie by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210298@lists.php.net to get a copy of this message
Note Submitter: mikeh at view22 dot com ---- Observed: 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. <?php function FreshenSessionCookie($lifetimeSeconds, $cookieName = 'PHPSESSID') { if (isset($_COOKIE[$cookieName])) { $data = $_COOKIE[$cookieName]; $timeout = time()+$lifetimeSeconds; setcookie($cookieName, $data, $timeout); } } ?>

« previous php.notes (#210298) next »