Welcome Guest, Not a member yet? Register   Sign In
CI Session class doesn't destroy session when the browser closes?
#1

[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?
#2

[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.
#3

[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)?
#4

[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?
#5

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

[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
#7

[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?
#8

[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").
#9

[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è
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB