Codeigniter设置在会话中记住我 [英] Codeigniter Setting Remember Me in Sessions
问题描述
我想实现记住我的功能到我的登录表单。当用户选中复选框或不是var_dumping会话过期数据返回63072000.我无法设置,我不明白为什么?
I'm trying to implement remember me function to my login form. When user checks the checkbox or not var_dumping the session expiration data is returning 63072000. I couldn't be able to set that and i don't understand why?
如何var_dump:
How i var_dump:
var_dump($this->session->sess_expiration); // returning 63072000
表单视图:
<input name="rememberme" value="rememberme" type="checkbox" />
登录模式:
$rememberme = $this->input->post('rememberme');
if((!isset($rememberme)) || ($rememberme != "rememberme")){
$this->session->sess_expiration = 10800; // 3 hours
$this->session->sess_expire_on_close = TRUE;
}
$this->session->set_userdata($data);
会话配置:
$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
推荐答案
根据论坛,会话数据设置从 config / config.php
文件,当会话类最初加载(我想你是自动加载或手动加载之前的模型中的代码),以后不能更改。
According to the forums at EllisLabs, the session data is set from the config/config.php
file when the Session Class is initially loaded (which I imagine you are either auto-loading or manually loading before this code in the model), and can't be changed afterwards.
然而,建议您可以更改会话数据。你可以尝试做的是在设置到期配置后强制更新会话数据,但仍然在 if
语句中:
Further down the thread however, it is suggested that you can change the session data. What you might try doing is forcing an update to the session data after setting the expiration configs, while still within the if
statement:
$rememberme = $this->input->post('rememberme');
if( (!isset($rememberme)) || ($rememberme != "remember me") ) {
$this->session->sess_expiration = 10800; // 3 hours
$this->session->sess_expire_on_close = TRUE;
$this->session->sess_update(); //Force an update to the session data
}
这篇关于Codeigniter设置在会话中记住我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!