1

I have a problem with my authentication in CakePHP. Whatever I try, Cake will either tell me I'm de-authenticated after each request, either I'm still authenticated, even though I closed the browser before.

I'll explain in a few words how my authenticating system works. The user logs in, with either remember me checkbox checked or not. If it's checked, I will create a cookie so as the user is auto-logged in the next time he visits the site. Basically, when the user closes his browser, I need to delete all the session cookies Cake stores in the browser. This way, when the user comes back, he sees the login page if he didn't want to be remembered, or is automatically logged in from the remember me cookie if he chose to store it.

The problem is I played with both Session.timeout and Security.level from core.php, with no positive results. If I put the timeout to 0, Cake will de-auth me after each request and I'm not able to view any page so. If I put any other value for timeout, the user might close the browser and when he re-opens it, he could be still logged in, as the Cake session didn't expire.

In conclusion, how can I automatically delete the session cookie whenever the browser is closed?

1 Answer 1

3

Take a look at this article maybe can helps you, I use something similar for other purpose.

http://bakery.cakephp.org/articles/admad/2009/09/02/how-to-bend-cakephp-s-session-handling-to-your-needs

see: ini_set('session.cookie_lifetime', 0);

2
  • Thank you! One thing still bothers me, though. Is Session.timeout from Cake the same thing with session.cookie_lifetime from php ini? Also, what value should my Session.save be set to? 'cake' or 'php'?
    – linkyndy
    Nov 13, 2010 at 12:30
  • How explained in article you have to create a php file with session configuration and save it in 'config' folder. If, for instance, you call it 'my_session' you have to write Configure::write('Session.save', 'my_session'); in 'core' file. Take a look in cake_session.php to understand how Session.timeout works in cakephp
    – riotera
    Nov 13, 2010 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.