Solved

How to set session inactivity timeout in php

Posted on 2008-10-12
2
1,749 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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