CodeIgniter Forums
CI3 Session Not Expiring On Browser Close - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CI3 Session Not Expiring On Browser Close (/showthread.php?tid=68710)



CI3 Session Not Expiring On Browser Close - elabuwa - 08-16-2017

Hi guys,

Using Codeigniter 3.1.2.

Below are my config details for session.

PHP Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 7200;
$config['sess_regenerate_destroy'] = FALSE

I am told that upon setting the sess_expiration to 0 that it would be destroyed upon browser close.

However, this does not seem to happen.

Any idea?
Any method I can use to utilise this?

Using javascript seems not practical since it gets triggered when used the back button and when going to a different URL.


RE: CI3 Session Not Expiring On Browser Close - pruthvidarji - 08-16-2017

It is possible if you change the sess_time_to_update with 1 day (means session destroy after 24 hour)


RE: CI3 Session Not Expiring On Browser Close - elabuwa - 08-16-2017

I need the session to be destroyed when the user closes the browser


RE: CI3 Session Not Expiring On Browser Close - InsiteFX - 08-16-2017

You can try this but make sure you clear your browsers cache before testing it again.

ini_set('session.cookie_lifetime', 0);


RE: CI3 Session Not Expiring On Browser Close - elabuwa - 08-16-2017

Thank you for the reply.

I added your code to the constructor of the of the default controller.

PHP Code:
public function __construct()
        {
                
parent::__construct();
                
ini_set('session.cookie_lifetime'0);
        } 

But it still seems to have no effect.
Any idea why?