Codeigniter-会话数据未通过数组保存在数据库中 [英] Codeigniter - Session data not saving in database via array

查看:111
本文介绍了Codeigniter-会话数据未通过数组保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入在Codeigniter中开发的登录程序的凭据时,会话似乎没有保存在MySQL数据库的ci_sessions表中.

When I enter my credentials for my login program developed in Codeigniter the sessions don't seem to be saving in the ci_sessions table in the MySQL database.

填写表格后,会话将在controller.php中设置(以下示例代码):

Once the form is filled in, the session will be set in the controller.php (sample code below):

if ($this->form_validation->run()) {
    $data = array(
       'email' => $this->input->post('email'), // posting the email input field
       'is_logged_in' => 1 
    );

$this->session->set_userdata($data);  

redirect('main/members');

} else {

    $this->load->view('login');

}  

目前,它在执行时输出以下内容:

At the moment its outputting the following when executing:

Array
(
   [__ci_last_regenerate] => 1440877455
   [email] => jhon@gmail.com
   [is_logged_in] => 1
)

输出在view.php中使用以下代码

The output is using the following code in view.php

print_r($this->session->all_userdata());

该数组应该在下面输出类似的内容,但不是:

The array should be outputting something similar below but its not:

Array
(
   [session_id] => dd7e0e2266da6481ef45faaa7e3c808b
   [ip_address] => 127.0.0.1
   [user_agent] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
   [last_activity] => 1387619782
   [user_data] => 
   [username] => Jhon
   [email] => jhon@gmail.com
)

config.php:

config.php:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

autoload.php

autoload.php

$autoload['libraries'] = array('database', 'session', 'form_validation');

$autoload['drivers'] = array('session');

$autoload['helper'] = array('url', 'form', 'html', 'security');

我已经检查了config.php以确保一切设置正确,并参考了Codeigniters网站上的手册,但仍然无法解决问题.

I have checked the config.php to ensure everything is set correctly and referred to the manual on Codeigniters website but still no joy in solving the issue.

为什么会这样?或任何可能的解决方案?

Any idea's as to why this is happening? OR Any possible solutions?

推荐答案

这里有很多问题...

There's a number of problems here ...

目前,它在执行时输出以下内容:

At the moment its outputting the following when executing:


Array
(
  [__ci_last_regenerate] => 1440877455
  [email] => jhon@gmail.com
  [is_logged_in] => 1
)

...

该数组应该在下面输出类似的内容,但不是:

The array should be outputting something similar below but its not:


Array
(
  [session_id] => dd7e0e2266da6481ef45faaa7e3c808b
  [ip_address] => 127.0.0.1
  [user_agent] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
  [last_activity] => 1387619782
  [user_data] => 
  [username] => Jhon
  [email] => jhon@gmail.com
)

不,不应该……您没有在任何地方设置用户名",其余的是

No it shouldn't ... you're not setting "username" anywhere and the rest is explained in the manual.

现在让我们检查您的配置...

Let's inspect your configuration now ...

$config['sess_driver'] = 'files';

^这行告诉库要使用什么存储.如果将其设置为文件",则不能期望将会话保存到数据库中...

^ This line is what tells the library what storage to use. If it is set to 'files', you cannot expect sessions to be saved to the database ...

$config['sess_encrypt_cookie'] = FALSE;

^此设置已过时;在CI 3.0.x上什么也不做.

^ This setting is obsolete; it does nothing on CI 3.0.x.

$ config ['sess_use_database'] = TRUE;

$config['sess_use_database'] = TRUE;

^由于已设置$config['sess_driver'],因此将忽略此设置-将其删除.

^ Since you have set $config['sess_driver'], this setting is ignored - remove it.

$config['sess_table_name'] = 'ci_sessions';

^这也将被忽略,并且您不应该将其与CI3一起使用.改为设置$config['sess_save_path'].

^ This is also ignored, and you shouldn't be using it with CI3. Set $config['sess_save_path'] instead.

$config['sess_save_path'] = NULL;

^您不应将其保留为NULL.库存config.php文件中的手册和内联注释都要求进行此设置!

^ You're not supposed to leave this to NULL. Both the manual and the inline comments in the stock config.php file say that setting this is REQUIRED!

$config['sess_match_useragent'] = FALSE;

^这在CI3中也不起作用.

^ This also does nothing in CI3.

$autoload['drivers'] = array('session');

^文档中没有任何内容表明这一点,并且它什么也没做.

^ Nothing in the documentation suggests this and it does nothing.

我已经检查了config.php以确保一切设置正确,并参考了Codeigniters网站上的手册,但仍然无法解决问题.

I have checked the config.php to ensure everything is set correctly and referred to the manual on Codeigniters website but still no joy in solving the issue.

相反,您甚至没有关注最基本的文档,这些都是配置文件中的简短描述……您显然只是从CodeIgniter 2.x复制粘贴了您的旧设置,而没有请按照升级说明.

On the contrary, you didn't pay attention even to the most basic documentation, which are short descriptions in the config files ... You've obviously just copy-pasted your old settings from CodeIgniter 2.x and didn't follow the upgrade instructions.

这篇关于Codeigniter-会话数据未通过数组保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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