简体   繁体   English

重定向后删除了Codeigniter会话

[英]Codeigniter session removed after redirect

I have an strange problem with (latest) Codeigniter. 我(最新)的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/ . 应用程序完成后,我将其上传到了我的Web服务器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. 感谢您的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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