duanbimo7212 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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?