Solved

How to set session inactivity timeout in php

Posted on 2008-10-12
2
1,747 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

792 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