简体   繁体   English

Codeigniter会话不起作用

[英]Codeigniter session won't work

I've been watching this tuts from yt how to build login system with Codeigniter 我一直在看这个来自如何使用Codeigniter建立登录系统的教程

Here is link from tutorial 这是教程的链接

when guy from video put this code to get user data 当视频中的家伙使用此代码获取用户数据时

<?php print_r ($this->session->all_userdata ());?>

he gets array with all data like in this video. 他获得了所有包含此视频中的数据的数组。 I receive array like this 我收到这样的数组

Array( [__ci_last_regenerate] => 1467913653)

So when try to login it always redirect me to restricted area even when email and password are good, and all should work. 因此,当尝试登录时,即使电子邮件和密码都不错,它也始终将我重定向到受限区域,并且一切正常。

Is it problem because I use Codeigniter 3, in video is CI 2? 是因为我使用Codeigniter 3,还是视频2,是问题吗?

make sure that session library is loaded you can auto load it from config/autoload.php as follows 确保已加载会话库,您可以从config / autoload.php自动加载它,如下所示

$config['libraries'] = array('session');

or load it in controller constructor as follows 或按以下方式将其加载到控制器构造函数中

$this->load->library('session');

and then you can get session data by call this method 然后您可以通过调用此方法获取会话数据

$this->session->userdata();

I hope my answer would be useful 我希望我的回答会有用

If you want to retrieve all of the existing userdata, you can simply omit the item key (magic getter only works for properties): 如果要检索所有现有的用户数据,则可以简单地省略item键(magic getter仅适用于属性):

$_SESSION

// or: // 要么:

$this->session->userdata();

Here is the documentation 是文档

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

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