Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Session Time Limit

Newbie
 
Join Date: Jul 2007
Posts: 10
#1: Aug 1 '07
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

Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#2: Aug 1 '07

re: PHP Session Time Limit


For clarity: did you build the site entirely, or is this something you have come across in someone else's code you are maintaining?
realin's Avatar
Familiar Sight
 
Join Date: Feb 2007
Posts: 252
#3: Aug 1 '07

re: PHP Session Time Limit


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
Newbie
 
Join Date: Jul 2007
Posts: 10
#4: Aug 1 '07

re: PHP Session Time Limit


Quote:

Originally Posted by Motoma

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!
Newbie
 
Join Date: Jul 2007
Posts: 10
#5: Aug 1 '07

re: PHP Session Time Limit


Quote:

Originally Posted by realin

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?
nathj's Avatar
Expert
 
Join Date: May 2007
Location: North Tyneside
Posts: 857
#6: Aug 2 '07

re: PHP Session Time Limit


Quote:

Originally Posted by jamesmcd999

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
volectricity's Avatar
Expert
 
Join Date: Jun 2007
Location: Baltimore
Posts: 587
#7: Aug 2 '07

re: PHP Session Time Limit


Quote:

Originally Posted by jamesmcd999

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.
Newbie
 
Join Date: Jul 2007
Posts: 10
#8: Aug 3 '07

re: PHP Session Time Limit


Quote:

Originally Posted by nathj

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
Newbie
 
Join Date: Jul 2007
Posts: 10
#9: Aug 3 '07

re: PHP Session Time Limit


Quote:

Originally Posted by volectricity

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
Newbie
 
Join Date: Jul 2008
Posts: 1
#10: Jul 6 '08

re: PHP Session Time Limit


Quote:

Originally Posted by realin

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