473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

php.ini session timeout

TheServant
1,168 Expert 1GB
What code do I need in my php.ini to timeout a session? Also, with garbage collection max life time, does that set the time of being idle before deleting the session, or does that se the life time (as the name would suggest)?

What I want is a user can be on the site for as long as they want, but if they are idle for 20min (no page requests), the session will be destroyed?
Apr 29 '08 #1
2 21432
coolsti
310 100+
There is something either in the server (Apache) set up or in php.ini that determines how long your session files live for before being deleted but I don't remember off hand where.

However, I handle this myself another way. I just have a variable saved along in the session array $_SESSION, for example $_SESSION['lastaccess'], which holds the time of the user's last page request. Each time the user makes a new page request, the current system time is compared to this session variable, and if the difference is larger than my allowed time out, I log the user out and present the user with the login page. If the time difference is smaller than the allowed time, then I set $_SESSION['lastaccess'] equal to the current time and serve the user the page he/she was asking for.

The reason I do it this way is because I do not just log the user out and destroy the session file, but I serialize the user's $_SESSION and $_POST arrays and store them in a database table. When the user logs in again, I check to see if there is an entry in this session-storage table for this user, and if so, I actually reconstruct where the user was trying to get to, and then remove the row for this user in the session-storage table.

In this manner, I effectively log the user out if the user is away from the computer for too long, but the user does not lose any work that he/she was doing. Because when the user successfully does log in again, the session and the page request is effectively restored, as if the user never was timed out.
Apr 29 '08 #2
TheServant
1,168 Expert 1GB
Thanks for that. That's a good idea. However, for what I want, I do not need to maintain session info, as the important stuff is called from my database, and I do not have a lot stored in my session. So if anyone can confirm the php.ini command is:
session.gc_maxlifetime = 10
And also let me know if there is a minimum timeout, that would be great!
Apr 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Geigho | last post by:
Setting session timeout in web.config file does not seem to have any effect. Any explanation or suggestion will be appreciated.
4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
8
by: Joe Abou Jaoude | last post by:
hi, I have a web app with forms authentication and a timeout session of 20 mins for security reasons. I recently added a feature that allows users (if they want to) to automatically log in...
11
by: Vishal | last post by:
Hello, can anybody tell me how I can extend the session expiry time? Is it done via code or via IIS? Sorry I am new and dont know about this.
5
by: Just D. | last post by:
Do we have any access to the Session object from a different Session? The idea is to save Session of a current user and then if he logs in again then return the Session back. It's not a problem to...
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
17
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
4
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change...
25
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
6
by: ChrisAtWokingham | last post by:
I have been struggling with unexpected error messages on an ASP.NET system, using SQL and C#. The application draws organisation charts, based on data stored in the SQL database. Some of the chart...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.