简体   繁体   中英

How to destroy session with browser closing in codeigniter 3

First of all I should remind you I have read this question , I am using Codeigniter 3 . I want to destroy session with browser closing like PHP session ! I have read somethings about using ajax like this :

var unloadHandler = function(e){
        //here ajax request to close session
  };
window.unload = unloadHandler;

and .... But I dont want to make myself dependent to js for destroy session with browser closing . this is my config.php

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'soheil_blog_name';

$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

You just have to set 'sess_expiration' to 0, as described in the manual and in the config.php comments .

Note: Technically, you can't really destroy the session when the browser is closed. You can only tell the browser to discard the session cookie after it is closed, but the session itself is still usable on the server-side (ie if you are the victim of a MITM attack and somebody stole the session ID).
The session is actually deleted later by the garbage collector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM