重定向后Codeigniter会话数据丢失 [英] Codeigniter session data lost after redirect

查看:72
本文介绍了重定向后Codeigniter会话数据丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter 2.1.0.

I am using codeigniter 2.1.0.

我正在尝试使用codeigniter中的会话库执行注册/登录功能.

I am trying to do a register/login function using the session library in the codeigniter.

使用会话库进行注册/登录对于localhost可以正常工作,但是当我将其投入使用并尝试使用时,该会话将无法正常工作.

The register/login with the session library worked fine for localhost, but when I put it live and tried it, the session does not work.

我的控制器登录以这种方式工作.我检查了凭据,确定后,我设置了会话数据并重定向到另一个页面.

My controller login works this way. I check the credentials, once ok I set my session data and redirect to another page.

$user_data = array(
                   'username'       => $result->user_name,
                   'email'          => $result->user_email,
                   'userid'         => $result->user_id,
                   'role'           => $result->user_role,
                   'login_state'    => TRUE,
                   'lastlogin'      => time(),
               );

$this->session->set_userdata($user_data);           
print_r( $this->session->all_userdata());            
redirect(base_url('dashboard'));

在这里,当我打印所有会话数据时,它们确实会打印出来.但是在仪表板控制器端,当我尝试打印会话数据时,它们不再存在.

at this point here when I print all my session data, they do print out. But at the dashboard controller side, when i attempt to print the session data out, they were not there anymore.

知道为什么吗?预先感谢您的帮助.

Any idea why? Thanks in advance for the help.

推荐答案

如果您在CI 3.x中工作,并且刚刚将服务器php版本升级到php 7.x

if you are working in CI 3.x and just upgraded your server php version to php 7.x

转到第281行的system/libraries/Session/session.php并将ini_set('session.name', $params['cookie_name']);替换为ini_set('session.id', $params['cookie_name']);

Go to system/libraries/Session/session.php at Line no 281 and replace ini_set('session.name', $params['cookie_name']); by ini_set('session.id', $params['cookie_name']);

这篇关于重定向后Codeigniter会话数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆