0
votes

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..

  1. I have set var $sess_table_name = 'ci_sessions'; & var $sess_use_database = TRUE; in Session class.
  2. I have also set $config['sess_use_database'] = TRUE; & $config['sess_table_name']= 'ci_sessions'; in config.php.
  3. I have created table in database like-

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

Give good solution about it.

Please help me.

1
Does your login work if you are not using the session table? Also did you set your encryption key?Marc Audet
DO NOT change Session.php in the core system files. Bad idea. Use config.php to set the relevant options.Marc Audet
You haven't mentioned if this is your dev environment or live but try clearing your cookies or changing the name of the cookie. I found when I went live I was having issues because the cookie for my dev and live environments had the same name causing conflicts which screwed up the sessions.Rick Calder
this is my dev environment or live and cookies name ci_sessionChandan Sroniyan

1 Answers

0
votes

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.