• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Igniter 1.7.3 database back sessions expire randomly

$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 0;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']         = 300;

My sessions that are database backed sometimes randomly expire and I lose the data in the session. I am using Code Igniter 1.7.3

That's because the Session library is doing it's garbage clean, in other words it is deleting all expired sessions.
// you need to raise this for a long time right now its set for 5 minutes
$config['sess_time_to_update'] = 300;


I thought the sess_time_to_update was how often it regenerates the session id and sess_expiration is when it expires (0 means never)

'time_to_update' = how many seconds between CI refreshing Session Information!

So if it is set to 5 minutes every 5 minutes it will create a new session_id
making your current session_id invalid!

Raise it to 900 and see how it acts.


[eluser]Jesus TG[/eluser]
Hi Friends,

I'm building a system with CodeIgniter 1.7.3 like you, and I'm having the same problems with the database session, I'm losing the info in the session and the users need to login again.

Did you found a solution for this problem? only I need to increase the "sess_time_to_update"!

These are my session variables:

$config['sess_cookie_name'] = 'rem_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

Jesus Trujillo

While less secure I ended up doing:

$config['sess_time_to_update'] = PHP_INT_MAX;

[eluser]Jesus TG[/eluser]
Thanks for your fast answer I'm going to do that!

Just I'm thinking... May be I can put the same value in the "sess_time_to_update" like "sess_expiration" = 7200.
So, The users will have the same time in the session expiration and in the session update.

What do you think?

That might work, I am not sure the way sessions work for code ignitor work.

Is 7200 the number of seconds the session will expire in if there is no activity?

[eluser]Jesus TG[/eluser]
The comments in the file /system/aplication/config/config.php say:

'session_expiration' = the number of SECONDS you want the session to last. By default sessions last 7200 seconds (two hours). Set to zero for no expiration.

But I'm going to try my web app with the new changes tomorrow and I'm going to check how it works Smile


Just a Note to everyone!

If you are using CodeIgniter 2.0.+ the Reactor Team change the Session table the one in the User Guide is wrong!

If your using this it may be your problem:
$config['sess_match_useragent'] = TRUE;

New ci_session table:
-- --------------------------------------------------------------

-- Table structure for CodeIgniter ci_sessions.
DROP TABLE IF 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,
  PRIMARY KEY (`session_id`)

-- -------------------------------------------------------------
--  `user_data`    text,        COMMENT - maximum length of 65535      characters.
--  `user_data`    mediumtext,  COMMENT - maximum length of 16777215   characters.
--  `user_data`    longtext,    COMMENT - maximum length of 4294967295 characters.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.