在我的config.php中
会议:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
和cookie:
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
我为默认会话做了这个配置,我将用于整个应用程序。
现在我需要在2小时后为显式超时设置一些cookie和会话,并将用户重定向到结束该测验竞赛会话。
$data = array(
'quiz_id' => 2,
'is_quiz_active' => true
);
$this->session->sess_expiration = '3600';// expires in 1 hours
$this->session->set_userdata($data);
if($this->session->userdata('is_quiz_active')) {
echo $this->session->userdata('is_quiz_active');
} else {
redirect(base_url(), 'refresh');
}