?
Solved

How to set session inactivity timeout in php

Posted on 2008-10-12
2
Medium Priority
?
1,751 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 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

800 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