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

查看:40
本文介绍了重定向后 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天全站免登陆