开发者

Session data disappear when using sess_use_database in codeigniter

Im creating a authentication for my web (currently im using codeigniter as my php framework).

How come when i set TRUE in the $config['sess_use_database'] = TRUE;

my session data's disappears and doesn't display in part of the page. Im trying to display the username of the person who login to the site.

When the $config['sess_use_database'] = FALSE; the username displays in the page.

anyone experience this problem? h开发者_JS百科ow can i resolve this?


In CodeIgniter 2, the ci_sessions table needs to be slightly different.

Specifically the size of user_agent has gone from varchar 50 to varchar 120. Make sure you use this basic prototype if you are using CodeIgniter 2 with sess_use_database set to TRUE:

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(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);

via http://codeigniter.com/user_guide/libraries/sessions.html


You need to create database table to store session data:

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)
);

And then set $config['sess_table_name'] = 'ci_sessions';

http://codeigniter.com/user_guide/libraries/sessions.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜