2016-09-01 110 views
1

我想將codeigniter版本3中的會話設置爲在瀏覽器關閉時到期。在瀏覽器上關閉會話關閉Codeigniter 3

我用Google搜索了下面的解決方案來解決這個問題。並在應用程序配置下更新下線

$config['sess_expiration'] = 0; 
$config['sess_expire_on_close'] = TRUE; 

此解決方案完美工作。

但問題是現在瀏覽器會話仍然是直到瀏覽器關閉這將是一個對待我的應用程序。

因此,我想保持10分鐘會話過期時間也。

所以從論壇尋求幫助,在我的應用程序中實現這兩種情況。

在此先感謝。

回答

0

我想你使用此代碼,在這裏你去:

var expireSessionVar = function(e){ 
    //HERE YOUR CODE WHATEVER YOU WANT 
}; 
window.unload = expireSessionVar; 

希望它會幫助你。

+0

是的,我已經這樣做了。但我想保持到期時間。請通讀這個問題。 – SamJ

0

應用程序\設置\ config.php文件

/* 
|-------------------------------------------------------------------------- 
| Session Variables 
|-------------------------------------------------------------------------- 
| 
| 'sess_cookie_name'  = the name you want for the cookie 
| 'sess_expiration'   = the number of SECONDS you want the session to last. 
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration. 
| 'sess_expire_on_close' = Whether to cause the session to expire automatically 
| when the browser window is closed 
| 'sess_encrypt_cookie'  = Whether to encrypt the cookie 
| 'sess_use_database'  = Whether to save the session data to a database 
| 'sess_table_name'   = The name of the session database table 
| 'sess_match_ip'   = Whether to match the user's IP address when reading the session data 
| 'sess_match_useragent' = Whether to match the User Agent when reading the session data 
| 'sess_time_to_update'  = how many seconds between CI refreshing Session Information 
| 
*/ 
$config['sess_cookie_name']  = 'ci_session'; 
$config['sess_expiration']  = 600; 
$config['sess_expire_on_close'] = TRUE; 
$config['sess_encrypt_cookie'] = FALSE; 
$config['sess_use_database'] = TRUE; 
$config['sess_table_name']  = 'dbapp_ci_sessions'; 
$config['sess_match_ip']  = TRUE; 
$config['sess_match_useragent'] = TRUE; 
$config['sess_time_to_update'] = 300; 

/* 

剛剛成立$config['sess_expiration']= 7200;$config['sess_expiration'] = 600;,這將設置你的會話每隔10分鐘過期。此外,如果您將$config['sess_expire_on_close'] = TRUE;設置爲指向,則每當瀏覽器關閉時,會話將被終止。

+0

你能解釋一下它將如何解決這兩個要求? – SamJ

+1

@SamJ默認會話終止時間是7200秒,相當於2小時,將7200更改爲600,以便您的會話在10分鐘後過期。 –

+0

@Fiasal $ config ['sess_expiration'] = 600正常工作,但$ config ['sess_expire_on_close'] = FALSE;解決方案不適用於瀏覽器關閉。 – SamJ