Killing session on browser close in Codeigniter
It may be well known to some people how to kill sessions on browser close but the default config in codeigniter doesn’t provide so. In lot of application which has admin interface, we don’t want browser to store the session. So it needs to kill the session when browser is closed. Example behavior can be found in yahoo email page.
So how do we do that in Codeigniter ? It’s simple, although this feature is not well commented or documented. Ok, now open system/application/config/config.php file
And find the settings called $config[‘sess_expiration’] under the section Session Variables and put the value like this
1 |
$config['sess_expiration'] = -1; |
That’s it. Now your session will be killed in the event of browser closing.
Hmm… you sure about this? I will have a look now and try it, cause i have been mucking around with the session class and i think it’s the most complete class in CI, very useful, but will let you know if this tip of yours works well 🙂
Nope, it doesn’t work, it wont let me login at all if i put the sess_expiration to -1 and if have been logged in and try to set it to -1 while i am logged in, it logs me out.
@Zoran : It works for me. I have used database to handle the session. If I’m logged in, i can browse the pages fine but when the browser closes, it doesn’t. Are you using db to handle the sessions ?
I use a database. It does not work!
It does not work for me too.
If you set $config[‘sess_expiration’] = -1; then you will not permit to pass the login page.
so if you have any update then please give so..
doesnt work for me either but I found this link http://codeigniter.com/wiki/PK_Session/revision/9541/
Btw I there is already a function for this sess_expire_on_close
yep – $config[‘sess_expire_on_close’] = TRUE;
It sis not working for me also.
not working for me at all..
This is not working for me.. This is totally wrong solution… Please updates as required…
It’s work for me . Need to browser close not browser TAB close .
it work !!!