I am trying to increase the session lifetime in cakephp app. I have a remember me
checkbox in login page. When checking the checkbox, I need to extend session time to 1 hour more to current time and any action inside the app after login will need to extend session time to 1 hour more.
I have component file for login and all action will be entered in startup function. I tried to extend the session.cookie
(CakePHP's session cookie) lifetime, but it didn't works.
function startup(&$controller) {
/* First try */
setcookie(Configure::read('Session.cookie'),$_COOKIE[Configure::read('Session.cookie')], time() + 3600, "/"); // Configure::read('Session.cookie') is 'CAKEPHP'.
/* Second try */
ini_set('session.gc_maxlifetime', 3600);
/* Third try */
session_set_cookie_params(time() + 3600);
echo $this->Session->read('status').' session <br/>';
echo $_SESSION['test'];
}
But all of these doesn't keep the session after session.timeout
(CakePHP's session timeout) time. The session status
and test
varaibles are created on login. It will be retrieved until session.timeout
is not reached.
I am using cakephp v1.2.
keep this in your core.php file
Configure::write('Session', array(
'defaults' => 'cake',
'timeout' => 14400, // 4 hours
'cookieTimeout' => 14400, // 4 hours
'cookie' => 'Your Cookie Name',
)
);
It is not a good idea to keep very high session timeout. If your requirement is only to keep him logged for more time, then use some auto_login component like www.milesj.me/resources/script/auto-login