1

我正在尝试在我的登录表单中实现记住我的功能。当用户选中复选框或不 var_dumping 会话过期数据返回 63072000。我无法设置它,我不明白为什么?

我如何 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;
4

1 回答 1

1

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.

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
}
于 2014-01-27T21:11:06.320 回答