note 78930 added to function.session-set-cookie-params

From: Date: Fri, 02 Nov 2007 19:38:08 +0000
Subject: note 78930 added to function.session-set-cookie-params
Groups: php.notes 
Request: Send a blank email to php-notes+get-131952@lists.php.net to get a copy of this message
The below note is an excellent example of how to 'reset' the session expiration time upon a page refresh. However, take care to compensate for when the session expires and doesn't renew itself (a bug I believe). If the below example is run every time a script is executed, it will give an 'Undefined index <session name> error' after the session fails to renew. Precede it with and if isset() condition. <?php private function startSession($time = 3600, $ses = 'MYSES') { session_set_cookie_params($time); session_name($ses); session_start(); // Reset the expiration time upon page load if (isset($_COOKIE[$ses])) setcookie($ses, $_COOKIE[$ses], time() + $time, "/"); } ?> The above example states that a session will last an hour without a page refresh until it is scrapped. Upon a page refresh, the expiration time is reset back to one hour again. If you wish to give users the option of 'staying logged in forever', just feed startSession a value of '99999999', which should last about 3 years. ---- Server IP: 66.207.199.35 Probable Submitter: 77.98.240.123 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-cookie-params.php Edit -- https://master.php.net/note/edit/78930 Del: integrated -- https://master.php.net/note/delete/78930/integrated Del: useless -- https://master.php.net/note/delete/78930/useless Del: bad code -- https://master.php.net/note/delete/78930/bad+code Del: spam -- https://master.php.net/note/delete/78930/spam Del: non-english -- https://master.php.net/note/delete/78930/non-english Del: in docs -- https://master.php.net/note/delete/78930/in+docs Del: other reasons-- https://master.php.net/note/delete/78930 Reject -- https://master.php.net/note/reject/78930 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131952) next »