如何在 codeigniter 3 数据库中设置会话?
我使用的是新版本(3.0.0).CodeIgniter 和我有一个新问题,我的会话不起作用.我的意思是,控制器中的代码是正确的,因为没有错误,但是,当我尝试在视图中打印 PHP 变量时,却什么也没有.
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.
我在 MySQL Server 中检查了我的表,什么也没有,我现在不知道是什么问题.我把我的config.php代码.(这个新版本很多东西看不懂)
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.
如果有人遇到同样的问题,请帮助我:(.我的 Session 类尚未编辑.
If somebody has the same problem, help me please :( . My Session class has not been edited.
首先 CI3 会话表 和 CI2 会话表(将会话数据保存到数据库)结构不同
First of all CI3 session table and CI2 session table( Saving Session Data to a Database)structure is different
新会话表结构
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;
在他们的文档
会话库可用的新特性(函数)很少.
Few new feature(function) available for session library.
记住在使用之前不要忘记通过autoload.php加载或者加载$this->load->library('session');
.
Remember Don't forget it to load via autoload.php or loading $this->load->library('session');
before use it.