0

I just want to inquire about how to make sessions in cakephp to last and be destroyed only when I click logout.

Currently, when I close the browser or just leave the computer, when I get back for like 1 hour, it prompts me to the login page, meaning the Session was deleted.

Facebook in a way does this - unless you logout, your session is stored, so even when you close your browser or leave your computer, you will always be logged in.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
comebal
  • 946
  • 3
  • 14
  • 30
  • The length of sessions is generally determined by settings in php.ini I believe. I believe setting them to zero will mean that the sessions lasts until the browser is closed, but longer than that I believe is impossible. – thatidiotguy Nov 13 '12 at 18:34
  • Hmmm.. I cant seem to find that setting when I checked the phpinfo() – comebal Nov 13 '12 at 18:37
  • Here related question: http://stackoverflow.com/questions/156712/php-what-is-the-default-lifetime-of-a-session – thatidiotguy Nov 13 '12 at 18:38
  • Do you want to make the session infinite, or are you talking about giving the user a "remember me" type of option on login which stores some sort of hashed login credential in a cookie? The reason I ask, is because making your session lengths extremely long (can't make infinite as far as I know) could eventually cause you to run out of disk space if using disk-based session storage, or severely degrade the performance of your session table if using db-backed sessions. – Mike Brant Nov 13 '12 at 18:42

1 Answers1

2

From the very top of Cake's Session docs:

Session.timeout - The number of minutes you want sessions to last.

and

Session.cookieTimeout - The number of minutes you want sessions to last. If this is undefined, the value from Session.timeout will be used.

Although you can't make them infinite, try increasingly bigger numbers until you're happy.

<?php
Configure::write('Session', array(
    'timeout' => 4320 //3 days
));
Ben Graham
  • 2,089
  • 17
  • 21