save session in database by CodeIgniter

放肆的年华 提交于 2020-01-06 02:49:06

问题


I want to save session in database.in CodeIgniter user guide , make an example to store some data in database.

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text DEFAULT '' NOT NULL,
PRIMARY KEY (session_id)
);

Now I want to store an extra data by session in datbase,for example request_token value.

$this->session->set_userdata('request_token','test');

How should I do it by session?


回答1:


Go to your config.php under application folder and set use session database option to true. Import the sql structure like you have there and use sessions like you have. It will store the session variable in db. You might want to enable session encryption as well.



来源:https://stackoverflow.com/questions/7280056/save-session-in-database-by-codeigniter

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