简体   繁体   中英

Codeigniter session removed after redirect

I have an strange problem with (latest) Codeigniter. I use the session class for my login. After login i store some userdata in the session.

I developed my application local and the login works fine. When the application was finished , i uploaded it to my webserver http://mijn.exova.nl/ . The application worked fine for a day. But a day later the session are not stored after the login. I uploaded the code again from local but the problem still exist. Before the redirect the session still exist. After the redirect the session is empty.

Code:

Config settings session (are default)

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$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['cookie_prefix']        = "";
$config['cookie_domain']    = "";
$config['cookie_path']  = "/";
$config['cookie_secure']    = FALSE;

Creation session (in library)

$this->CI->session->set_userdata('exova_login', true);
$this->CI->session->set_userdata('exova_userdata', $userdata);
$this->CI->session->set_userdata('exova_rollen', $rollen);
$this->CI->session->set_userdata('exova_school', $school);

Redirect (before session is oke, after the session is empty)

redirect(base_url());

Does somebody know why this problem occured? Thanks!

It works again! The exact problem is unknown but when i removed all browser data it works again. I learned that it is very importend to set session not twice. I solved it by adding this:

if($this->CI->session->userdata('exova_login') == false){

arround the session set. Session will never be set twice and that ensured that problems like these can be avoided. Thanks for the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM