Solved

How to set session inactivity timeout in php

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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.
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…
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…

708 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