Codeigniter会话数据登录后在其他页面中不可用 [英] Codeigniter Session Data not available in other pages after login

查看:111
本文介绍了Codeigniter会话数据登录后在其他页面中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我设置了一个登录页面,验证用户的凭据,然后设置codeigniter会话数据'email'和'is_logged_in'和一些其他项目。登录后的第一页,数据是可访问的。在该页面之后,我无法再访问会话数据。事实上,如果我尝试重新加载第一页,会话数据已经消失。

So, I have set up a login page that verifies the user's credentials, and then sets codeigniter session data 'email' and 'is_logged_in' and a few other items. The first page after the login, the data is accessible. After that page, I can no longer access the session data. In fact, if I try reloading that first page, the session data is gone.

我已经尝试将其存储在数据库中,存储它未加密(坏主意,我知道,但它是用于故障排除),并将其加密存储。我已经自动加载会话库在config.php。

I have tried storing it in the database, storing it unencrypted (bad idea I know, but it was for troubleshooting), and storing it encrypted. I have autoloaded the session library in config.php.

以下是我用来设置会话数据的代码示例:

Here's an example of the code I'm using to set the session data:

$data = array(
                    'email' => $this->input->post('username'),
                    'is_logged_in' => true 
                );
                $this->session->set_userdata($data);

并且要检索它,我使用:

And to retrieve it, I'm using :

$this->session->userdata('email');

$this->session->userdata('is_logged_in');

我已经做了很多PHP和cookies以及会话的工作,但这是我的第一个项目与Codeigniter,我很困惑。

I've done lots of work with PHP and cookies, and sessions before, but this is my first project with Codeigniter and I'm perplexed.

它可以与目录问题有关吗?我有一个登录页面和过程由一个登录控制器控制,然后它重定向到一个站点控制器。

Could it have something to do with directory issues? I have the login page and process controlled by a 'login' controller, and then it redirects to a 'site' controller.

感谢您的帮助,如果我需要澄清任何内容,请通知我。

Thanks for your help, and please let me know if I need to clarify anything.

推荐答案

您的代码看起来不错。我在Codeigniter的会话库中遇到了很多问题,包括类似于你提到的问题。

Your code looks fine. I've had numerous issues with Codeigniter's session library, including something similar to what you mentioned.

请考虑查看 Native Session 库解决您的问题。

Consider looking at the Native Session library to resolve your issue.

这篇关于Codeigniter会话数据登录后在其他页面中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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