CodeIgniter Forums
CI Session class doesn't destroy session when the browser closes? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CI Session class doesn't destroy session when the browser closes? (/showthread.php?tid=37601)

Pages: 1 2


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]dtrenz[/eluser]
I'm aware that CI stores it's sessions in a cookie, but it appears that the CI Session class doesn't auto-destroy the session, as a browser session does ($_SESSION). Is that correct?


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]WanWizard[/eluser]
That depends on how you have configured it (like you have to do for PHP's native sessions).

For CI 1.7.x, you have to do a bit of hacking to archive this, for CI 2.0 it's supported out of the box. See the manual on how to configure sessions.


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]dtrenz[/eluser]
Thanks. I'm using 2.0 and I have "sess_expire_on_close" set to TRUE but it's not expiring the session when I close the browser. Do any other session configs affect this setting (i.e. sess_expiration)?


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]WanWizard[/eluser]
No. You're sure you close the entire browser, and not just the window or tab that contains your site?

If so, can you check in your browser what the expiry time of the session cookie is?


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]dtrenz[/eluser]
Yep. I completely quit my browser. Expiry is tomorrow.


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-14-2011

[eluser]cideveloper[/eluser]
I had the same problem.. I moved over to CI2 specifically for this feature and since it didnt work, I backed out back to 1.7 with the hacks


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-15-2011

[eluser]WanWizard[/eluser]
I can't reproduce this.

I've just installed CI2 from tip, set the session encryption key, and sess_expire_on_close to TRUE, and loaded the session library in the welcome controller. It creates a cookie that expires "at end of browser session" according to my browser.

So what did you exactly do? How did you configure it? Are you using a third party session library, a MY_Session library, or other modifications?


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-17-2011

[eluser]dtrenz[/eluser]
Here is my Test controller:
Code:
<?php

class Test extends Controller {

    public function set()
    {
        $this->session->set_userdata('test', 'session exists');
    }

    public function get()
    {
        var_dump($this->session->userdata('test'));
    }

}

Here are the steps to reproduce:

1. go to http://mydomain.com/test/set; session data is stored.
2. go to http://mydomain.com/test/get; session data is retrieved/displayed (string(14) "session exists").
3. quit browser.
4. open browser, and go to http://mydomain.com/test/get; session data is retrieved/displayed (string(14) "session exists").


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-17-2011

[eluser]Cristian Gilè[/eluser]
Are you working on a mac? To destroy the session when the browser closes I need, not only to close it, but also, right click on the browser icon in the dock and choose exit.


Cristian Gilè


CI Session class doesn't destroy session when the browser closes? - El Forum - 01-17-2011

[eluser]dtrenz[/eluser]
That is correct. I am using Google Chrome on Mac OS X. I right-click Chrome in the dock and quit (or Command+Q). The browser is completely shutdown.