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 に答える