How to destroy session with browser closing in codeigniter 3

帅比萌擦擦* 提交于 2019-12-10 19:45:28

问题


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;

回答1:


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 (i.e. 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.



来源:https://stackoverflow.com/questions/33388856/how-to-destroy-session-with-browser-closing-in-codeigniter-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!