By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

PHP Session Time Limit

P: 10
I am currently developing a site and noticed that after about 2 minutes, I am being logged out of the members area.

I have been trying to find a function that will allow me to specify the time limit but I have been unable to find an example of the where to place the function (i.e at the top of the page with the rest of the session info).

Can someone please provide me with a function, how to use it and where about it goes in the script.

Regards
James
Aug 1 '07 #1
Share this Question
Share on Google+
9 Replies


Motoma
Expert 2.5K+
P: 3,237
For clarity: did you build the site entirely, or is this something you have come across in someone else's code you are maintaining?
Aug 1 '07 #2

realin
100+
P: 254
well if u talking about sessions, then u surely can do it with ini_set if you donn wanna mess around with php.ini

this worked for me

Expand|Select|Wrap|Line Numbers
  1.   ini_set('session.gc_maxlifetime',14400);
  2.   ini_set('session.gc_probability',1);
  3.   ini_set('session.gc_divisor',1); 
ofcourse u can replace 14400 by ur custom seconds
Aug 1 '07 #3

P: 10
For clarity: did you build the site entirely, or is this something you have come across in someone else's code you are maintaining?
I built the site entirely!
Aug 1 '07 #4

P: 10
well if u talking about sessions, then u surely can do it with ini_set if you donn wanna mess around with php.ini

this worked for me

Expand|Select|Wrap|Line Numbers
  1.   ini_set('session.gc_maxlifetime',14400);
  2.   ini_set('session.gc_probability',1);
  3.   ini_set('session.gc_divisor',1); 
ofcourse u can replace 14400 by ur custom seconds

Thanks, Where do i place this in the page? Does it matter?
Aug 1 '07 #5

nathj
Expert 100+
P: 938
Thanks, Where do i place this in the page? Does it matter?
I'm not sure if it matters, but I always put this sort of thing at the top - before anything else - the place you would put session_start().

That has always worked for me.

Cheers
nathj
Aug 2 '07 #6

kovik
Expert 100+
P: 1,044
Thanks, Where do i place this in the page? Does it matter?
The session garbage collector works off of this information, so do it before session_start(), or the expired sessions will be removed before you get a chance to alter the settings.
Aug 2 '07 #7

P: 10
I'm not sure if it matters, but I always put this sort of thing at the top - before anything else - the place you would put session_start().

That has always worked for me.

Cheers
nathj

Thanks for that Nathj
Aug 2 '07 #8

P: 10
The session garbage collector works off of this information, so do it before session_start(), or the expired sessions will be removed before you get a chance to alter the settings.

Cheers mate

James
Aug 2 '07 #9

P: 1
well if u talking about sessions, then u surely can do it with ini_set if you donn wanna mess around with php.ini

this worked for me

Expand|Select|Wrap|Line Numbers
  1.   ini_set('session.gc_maxlifetime',14400);
  2.   ini_set('session.gc_probability',1);
  3.   ini_set('session.gc_divisor',1); 
ofcourse u can replace 14400 by ur custom seconds
Thanks for the code. You saved me a nightmare!!!! Works beautifully.
Jul 6 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.