Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$SESSION maxlife - how to set? 1

Status
Not open for further replies.

XgrinderX

Programmer
Joined
Mar 27, 2001
Messages
225
Location
US
I have written a little admin function for a segment of a web site and when a user logs in with the correct admin credentials, then I set a session variable to say that they are logged in and I check that session variable for every page within the admin section.

However, users are reporting that if it takes them a little while to fill in some forms, then when they click submit they are being kicked out.

Is there a way for me to set the life time of the session vars within my PHP code? Or is there a better way to handle what I am trying to do?

Thanks,

-Greg
 
The lifetime of session variables are set by the interaction of a number of PHP runtime configuration directives.

session.cookie_lifetime sets in seconds the life of the session cookie. This defaults to zero, which means the cookie lasts until the browser shuts down.

session.gc_maxlifetime sets the number of seconds after which the session store on the server is determined to be garbage and eligible for removal by the garbage-collection process.

session.gc_probability and session.gc_divisor determin the probability that the garbage-collection process will begin when session_start() is invoked. (session.gc_probability/session.gd_divisor) * 100 gives the percent chance that the garbage collection mechanism will operate. (session.gc_divisor defaults to 100).


Generally, I set session.cookie_lifetime to zero, session.gc_probability to 100, and session.gc_maxlifetime to the number of seconds I want the session to last.

You can change these settings in php.ini, httpd.conf and .htaccess files (if on Apache), or by using ini_set()



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks for the tips sleipnir, I don't think I have access to edit the php.ini file directly since I am not hosting the site directly....or at least I can't find it anyway :)

I will use the ini_set() function to change those values and see if that solves the problem.

Here's one other question - do I have to put the session_start() call on every page that I am using a session variable?
 
Yes. Unless you set the PHP runtime configuration directive session.auto_start to "on" in php.ini, httpd.conf, or a .htaccess file. Although you can set session.auto_start in a script using ini_set(), there wouldn't be much point in it.

Also, since the function may cause headers to be sent to the user's browser, session_start() must appear in a point in your script before your script has output any content.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top