2015-10-28 56 views
3

首先我應該提醒你我已經閱讀this question,我正在使用Codeigniter 3。 我想用瀏覽器關閉像PHP會話一樣的會話! 有關使用AJAX這樣我已經閱讀出頭:如何在瀏覽器中關閉codeigniter 3

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

和.... ,但我不想讓自己依賴於JS與瀏覽器關閉破壞會議。 這是我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

http://stackoverflow.com/questions/13174297/how-to-destroy-session-with-browser-closing-in-codeigniter – Saty

+0

這是不是笨3 –

回答

5

你只需要「sess_expiration」設置爲0,如manual並在config.php comments描述。

注意:從技術上講,瀏覽器關閉時不能真正銷燬會話。您只能告訴瀏覽器在會話cookie關閉後放棄會話cookie,但會話本身在服務器端仍然可用(即,如果您是MITM攻擊的受害者並且有人偷走了會話ID)。
會話實際上被垃圾收集器刪除。

+0

請記住,即使使用'sess_expiration'設置爲0,如果用戶正在使用瀏覽器設置'繼續你離開的位置',瀏覽器甚至不會刪除cookie。因此,並非Codeigniter做錯了事情,只是在某些情況下,瀏覽器本身可能導致此功能無法按預期工作。這個問題在這個問題中進一步討論:http://stackoverflow.com/questions/10617954/chrome-doesnt-delete-session-cookies – justanotherprogrammer