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

#1
[eluser]blasto333[/eluser]
Code:
$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

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

InsiteFX

#3
[eluser]blasto333[/eluser]
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)

#4
[eluser]InsiteFX[/eluser]
'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.

InsiteFX

#5
[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;




Thanks,
Jesus Trujillo

#6
[eluser]blasto333[/eluser]
While less secure I ended up doing:

$config['sess_time_to_update'] = PHP_INT_MAX;

#7
[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?

#8
[eluser]blasto333[/eluser]
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?

#9
[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

Thanks,
JT

#10
[eluser]InsiteFX[/eluser]
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:
Code:
$config['sess_match_useragent'] = TRUE;

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

--
-- Table structure for CodeIgniter ci_sessions.
--
DROP TABLE IF EXISTS `ci_sessions`;

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,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

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

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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