[英]Codeigniter 3 sessions not functioning correctly
I have dug through all the codeigniter session topics, but have not found any solutions. 我已经遍历了所有codeigniter会话主题,但没有找到任何解决方案。
I have setup a Login Controller for my project that sends the username and password onto my Login Model. 我为我的项目设置了一个登录控制器,该控制器将用户名和密码发送到我的登录模型上。 This all works fine.
这一切都很好。 Once I pull the information out of the database, I am setting some session information.
一旦我从数据库中提取信息,就可以设置一些会话信息。
Here are some code snippets: Config: 以下是一些代码段:配置:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 14400;
$config['sess_save_path'] = '/var/www/mysite.com/application/cache/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 0;
$config['sess_regenerate_destroy'] = FALSE;
Autoload: 自动加载:
$autoload['libraries'] = array('session', 'database', 'form_validation', 'email');
Pulling an idea from the database (works fine): 从数据库中提取一个想法(工作正常):
$UserID = $this->LoginModel->login($username, $pass);
Setting a session variable: 设置会话变量:
$this->session->set_userdata('Sess_ID', md5($UserID.date('YmdHis')));
After the process is complete, the user is sent to the next page. 该过程完成后,用户将被转到下一页。 This is where the problems are.
这就是问题所在。 I load a simple check for the session variables and even a var_dump, but every time the session is empty.
我为会话变量甚至是var_dump加载了一个简单的检查,但是每次会话为空时。
public function __construct() {
parent::__construct();
echo var_dump($this->session);
if ($this->SessionModel->basic() == false) {
//$this->SessionModel->logout();
echo 'Session Error';
}
}
So, the question is, how can I call the session from the next page/controller? 因此,问题是,如何从下一页/控制器调用该会话? I am used to using the session_start(), but that isn't needed in codeigniter.
我习惯于使用session_start(),但在codeigniter中并不需要。 I have also confirmed that session files can and are being written to the directory.
我还确认了会话文件可以并且正在被写入目录。
Input please... 请输入...
to get all session data use: 获取所有会话数据使用:
print_r($this->session->all_userdata());
for specific data: 对于特定数据:
print_r($this->session->userdata('name_of_the_session_variable');
in your case: 在您的情况下:
print_r($this->session->userdata('Sess_ID'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.