Solved

How to set session inactivity timeout in php

Posted on 2008-10-12
2
1,745 Views
Last Modified: 2011-04-14
How do I configure the session inactivity timeout in php?  I have users who take a long time filling out complicated forms.  Their session is getting deleted before they submit the forms.

I would prefer to control this timeout under program control so that only the complicated forms have the long timeout.  However, if necessary, I will set it for the entire server.  What are my options?
0
Comment
Question by:olszowka
2 Comments
 
LVL 9

Accepted Solution

by:
Sander Stad earned 250 total points
ID: 22700791
This can be done by using the ini_set function in PHP. Look at this code:
 

// Get the actual session timeout
$currentTimeoutInSecs = ini_get(session.gc_maxlifetime);
// Set the session timeout
ini_set(session.gc_maxlifetime, 30*60);

Open in new window

0
 
LVL 7

Assisted Solution

by:marklogan
marklogan earned 250 total points
ID: 22701807
Depending on your host (you don't say if you have your own server, or a shared host), some disabled the int_set function and you will not be able to set the value. You will have to ask them to change it in the php.ini file.

Some hosts let you create your own php.ini file to overwrite some values, or if it is your own server you can change the php.ini file which will change the variable globally across all files which will mean you dont have to use the int_set function.
; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
 
session.gc_maxlifetime = 1440

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now