note 78624 added to function.setcookie

From: Date: Fri, 19 Oct 2007 18:56:43 +0000
Subject: note 78624 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-131561@lists.php.net to get a copy of this message
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); } } ---- Server IP: 69.147.83.197 Probable Submitter: 207.245.26.111 ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/78624 Del: integrated -- https://master.php.net/note/delete/78624/integrated Del: useless -- https://master.php.net/note/delete/78624/useless Del: bad code -- https://master.php.net/note/delete/78624/bad+code Del: spam -- https://master.php.net/note/delete/78624/spam Del: non-english -- https://master.php.net/note/delete/78624/non-english Del: in docs -- https://master.php.net/note/delete/78624/in+docs Del: other reasons-- https://master.php.net/note/delete/78624 Reject -- https://master.php.net/note/reject/78624 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131561) next »