2015-05-06 19:56
浏览 68

如何在codeigniter 3数据库中设置会话?

I'm using the new version(3.0.0). of CodeIgniter and I have a new problem, my sessions doesn't work. I mean, the code in the controller is correct because there are not errors but, when I try to print a PHP variable in a view there is nothing.

I checked my table in the MySQL Server, and nothing, I don't now what is the problem. I put my code of config.php. (I don't understand a lot of things in this new version)

$config['sess_table_name']              = 'ci_sessions';
$config['sess_driver']              = 'database';
$config['sess_cookie_name']             = 'ci_session';
$config['sess_expiration']          = 7200;
$config['sess_save_path']               = NULL;
$config['sess_match_ip']                = FALSE;
$config['sess_time_to_update']      = 300;
$config['sess_regenerate_destroy']  = FALSE;

I have to add the first line to "make" sessions works, I don't know if that configuration is correct to make sessions in a database.

If somebody has the same problem, help me please :( . My Session class has not been edited.

图片转代码服务由CSDN问答提供 功能建议

我正在使用新版本(3.0.0)。 CodeIgniter和我有一个新问题,我的会话不起作用。 我的意思是,控制器中的代码是正确的,因为没有错误但是,当我尝试在视图中打印PHP变量时什么都没有。

我在MySQL中检查了我的表 服务器,没什么,我现在不是什么问题。 我把我的config.php代码。 (我不太了解这个新版本中的很多内容)

  $ config ['sess_table_name'] ='ci_sessions'; 
 $ config ['sess_driver']  ='database'; 
 $ config ['sess_cookie_name'] ='ci_session'; 
 $ config ['sess_expiration'] = 7200; 
 $ config ['sess_save_path'] = NULL; 
 $ config ['sess_match_ip  '] = FALSE; 
 $ config ['sess_time_to_update'] = 300; 
 $ config ['sess_regenerate_destroy'] = FALSE; 

我必须添加 “make”会话的第一行是有效的,我不知道在数据库中进行会话是否正确。

如果有人遇到同样的问题,请帮帮我:( 我的Session类尚未编辑。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dpkt17803 2015-05-06 21:21

    First of all CI3 session table and CI2 session table( Saving Session Data to a Database)structure is different

    New session table structure

     CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(40) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        PRIMARY KEY (id),
        KEY `ci_sessions_timestamp` (`timestamp`)

    Second They support old configuration variables with new configuration but it is better to use new configuration

    $config['sess_driver'] = 'database';
    $config['sess_cookie_name'] = 'ci_sessions';
    $config['sess_expiration'] = 7200;
    $config['sess_save_path'] = 'ci_sessions';//its your table name name
    $config['sess_match_ip'] = FALSE;
    $config['sess_time_to_update'] = 300;

    See more details at their docs

    Few new feature(function) available for session library.

    Remember Don't forget it to load via autoload.php or loading $this->load->library('session'); before use it.

    打赏 评论
  • douni1396 2015-05-06 20:03

    If you added the "first line" (i.e. sess_table_name) to make it work, that is because your sess_driver value is set to database. Take a look at the list of supported drivers and you will see that for file based sessions, it will default to that. In other words, if you remove these lines, it should work:

    $config['sess_table_name']          = 'ci_sessions';
    $config['sess_driver']              = 'database';
    打赏 评论
  • doudi1978 2015-05-06 20:50

    Remove that added line and set:

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

    Rest of code should be ok. Link to docs.

    打赏 评论
  • douci2022 2016-10-02 22:00

    Try this :

    $config['sess_save_path'] = sys_get_temp_dir();
    打赏 评论

相关推荐 更多相似问题