How I can set a session in codeigniter 3 database?

China☆狼群 提交于 2019-11-28 08:27:27

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.

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';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!