问题描述
我是新的php与codeigniter。我有一个关于php会话与codeigniter mvc框架的问题。
当我由于会话过期而无法在我们的网站登录时,我使用表(ci-sessions)存储会话数据。
I am new for php with codeigniter. I have a issue about php session with codeigniter mvc framework.When I have used table(ci-sessions) to store session data when I can not login in our site due to session expiration..
- 我已设置
var $ sess_table_name ='ci_sessions';
&var
$ sess_use_database = TRUE; - 我还设置了
$ config ['sess_use_database'] = TRUE;
&
$ config ['sess_table_name'] ='ci_sessions';
- I have set
var $sess_table_name = 'ci_sessions';
&var$sess_use_database = TRUE;
in Session class. - I have also set
$config['sess_use_database'] = TRUE;
&$config['sess_table_name']= 'ci_sessions';
in config.php. I have created table in database like-
CREATE TABLE如果不存在 ci_sessions
(
session_id varchar(40) DEFAULT'0'NOT NULL,
ip_address varchar(45)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
)
);
CREATE TABLE IF NOT EXISTS ci_sessions
(session_id varchar(40) DEFAULT '0' NOT NULL,ip_address varchar(45) 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
));
给出良好的解决方案。
请帮助我。
推荐答案
关于会话到期,请转到application-> config-> config。 php并设置$ config ['sess_expiration']等于零($ config ['sess_expiration'] = 0;)。
Regarding Session expiration, goto application->config->config.php and set $config['sess_expiration'] equal to zero ($config['sess_expiration']=0;). That will cancel the session expiration.
关于在表中保存会话,请确保您的表格看起来像这样:
Regarding saving the session in a table, make sure that your table looks something like this:
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) 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`)
);
当然,您可以向其中添加字段,但要牢记这一结构。
Of course you can add fields to it but keep that structure in mind.
这篇关于如何在表中保存会话数据而不获得过期会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!