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

From: Date: Thu, 28 Oct 2010 14:42:27 +0000
Subject: note 100657 added to function.session-set-cookie-params
Groups: php.notes 
Request: Send a blank email to php-notes+get-173555@lists.php.net to get a copy of this message
As PHP's Session Control does not handle session lifetimes correctly when using session_set_cookie_params(), we need to do something in order to change the session expiry time every time the user visits our site. So, here's the problem. <?php $lifetime=600; session_set_cookie_params($lifetime); session_start(); ?> This code doesn't change the lifetime of the session when the user gets back at our site or refreshes the page. The session WILL expire after $lifetime seconds, no matter how many times the user requests the page. So we just overwrite the session cookie as follows: <?php $lifetime=600; session_start(); setcookie(session_name(),session_id(),time()+$lifetime); ?> And now we have the same session cookie with the lifetime set to the proper value. ---- Server IP: 69.147.83.197 Probable Submitter: 85.130.9.109 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-cookie-params.php Edit -- https://master.php.net/note/edit/100657 Del: integrated -- https://master.php.net/note/delete/100657/integrated Del: useless -- https://master.php.net/note/delete/100657/useless Del: bad code -- https://master.php.net/note/delete/100657/bad+code Del: spam -- https://master.php.net/note/delete/100657/spam Del: non-english -- https://master.php.net/note/delete/100657/non-english Del: in docs -- https://master.php.net/note/delete/100657/in+docs Del: other reasons-- https://master.php.net/note/delete/100657 Reject -- https://master.php.net/note/reject/100657 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173555) next »