CodeIgniter Forums

Full Version: Killing session on browser close
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Keep the session at ci_session table.

How do I kill the browser closes the session?

El Forum

[eluser]richthegeek[/eluser]
The session data is held in the ci_session table, however the session ID is stored by the user in a cookie with the expiry time set to the time it was created (less than the current time when teh browser is closed, so it is destroyed).

The session cookie expires when the browser is closed, and I assume the CI session class has some sort of garbage collection mechanism to remove old session entities.

El Forum

[eluser]Unknown[/eluser]
hi, hede hode.
i had problem you have got.
my solution is:
in the folder system/libraries/session.php
class CI_session, function _set_cookie()
modify
Code:
setcookie(
                        $this->sess_cookie_name,
                        $cookie_data,
                        $this->sess_expiration + time(),
                        $this->cookie_path,
                        $this->cookie_domain,
                        0
                    );
to
Code:
setcookie(
                        $this->sess_cookie_name,
                        $cookie_data,
                        0,
                        $this->cookie_path,
                        $this->cookie_domain,
                        0
                    );
then you will get what you want.

El Forum

[eluser]WanWizard[/eluser]
It's better to make a library extension, then to modify the CI core code. When you upgrade, you'll loose your modifications.

And talking about upgrades, CI 2.0 has a config setting for 'expire on browser close', which works out of the box.

@richthegeek,

Yes, the session library does garbage collection, based on the gc_probability value (between 0 and 100) in the configuration.

El Forum

[eluser]GusDeCooL[/eluser]
[quote author="weigetc" date="1292242939"]hi, hede hode.
i had problem you have got.
my solution is:
in the folder system/libraries/session.php
class CI_session, function _set_cookie()
modify
Code:
setcookie(
                        $this->sess_cookie_name,
                        $cookie_data,
                        $this->sess_expiration + time(),
                        $this->cookie_path,
                        $this->cookie_domain,
                        0
                    );
to
Code:
setcookie(
                        $this->sess_cookie_name,
                        $cookie_data,
                        0,
                        $this->cookie_path,
                        $this->cookie_domain,
                        0
                    );
then you will get what you want.[/quote]

No Good!
Never ever edit the core file. Create your own extention.