Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy CakePHP session when close browser

I need to keep Security.level set on medium for Ajax reason. But I want that If the user close browser his session will destroy. How can I do that?

Thanks in advance!

like image 531
albertopriore Avatar asked Jul 25 '26 12:07

albertopriore


2 Answers

Config/core.php

Configure::write('Session', array(
    'defaults' => 'php',
    'cookieTimeout' => 0,   //Lives until the browser is closed.
    'checkAgent'  => false  //To fix a little the Chrome Frame problem
));
like image 196
dbwhddn10 Avatar answered Jul 27 '26 02:07

dbwhddn10


Unless you're persisting session data (ie: storing session data in a cookie with an expiration date in the future), then the session should be destroyed when the user closes the browser.

Unfortunately I'm not familiar with the CakePHP framework so I cannot comment on its API. However, if you want to explicitly end a session you can do so in PHP with session_destroy().

Hope that helps.

like image 35
Brian Driscoll Avatar answered Jul 27 '26 02:07

Brian Driscoll