为什么Codeigniter会话在关闭浏览器后不会过期? [英] Why the Codeigniter session does not expire after closing the browser?

查看:343
本文介绍了为什么Codeigniter会话在关闭浏览器后不会过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户 A 登录到应用程序,则会话中设置的用户ID。执行某些任务后,用户 A 关闭其浏览器并离开计算机。很快,用户 B 来了,打开浏览器,看到应用程序处于登录状态。用户 B 也可以打开内部网址,通过使用上一个会话将其直接重定向到应用程序中,而不进行任何身份验证。

If a user A logs into the application then the user id set in session. After doing some tasks user A closes his browser and leaves the computer. Short time later, user B came and open browser and see the application was in logged in state. User B can also open an internal url, which directly redirects him into the application without any authentication by using the previous session.

$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;


推荐答案

您可以覆盖或设置动态配置项。如果你只是看看 $ config ['sess_expire_on_close'] = TRUE;
是否使会话在浏览器窗口关闭时自动过期。

You can override or Set a Config Item dynamically. If you simply look at $config['sess_expire_on_close'] = TRUE; Whether to make the session to expire automatically when the browser window is closed.

如果用户未选中记住我复选框,请将其设置为true。并且会话将在用户关闭浏览器后过期。

Set it to true if user did not check the remember me checkbox. And the session will expire after user close the browser.

如果他检查记住我复选框,请将$ config ['sess_expire_on_close']设置为FALSE如

And if he checks the remember me checkbox, set $config['sess_expire_on_close'] to FALSE like

if($this->input->post('remember')) $this->config->set_item('sess_expire_on_close', '0'); //'remember' is checkbox name.

现在会话不会在浏览器关闭后过期。
注意:此解决方案还在Opera,Mozilla,Chrome和ie9上测试

now session will not expire after browser is closed. note: this solution is also tested on Opera, Mozilla, Chrome and ie9

这篇关于为什么Codeigniter会话在关闭浏览器后不会过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆