Automatically Session expires

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Automatically Session expires

Post by vinoth »

Hi,

I have some trouble with sessions. I wrote a
login-srcipt based on sessions. It works fine. But now
I want that after ten minutes of inactivity the users
are automatically logged out. But I don't know how to
realize it. I am using PHP 5.
Can someone help me?
Thanks in advance,


Vinoth
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Logged out... or to have the session expire?

To have the session expire, set the session.gc_max_lifetime in your php.ini file to 600 seconds (10 minutes). You can also be able to do this with ini_set().

If you want to do it with the code, you could store the time() in the session on each page load and compare it to the current time() on a subsequent page load.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's suggested to use the time() based method instead of trying to get the garbage collection system to do it for you.
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Post by vinoth »

How we control the session expires through time() function.

I didnot got your suggesstion please explain in detail
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The time() based method places the management responsibility in your code. Specifically, you store a timestamp in their session data. You check this timestamp against the current timestamp.. If your logic considers it expired, then your code would delete the session data and log out the user bringing them back to a default, browsing state.
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Re: Automatically Session expires

Post by vinoth »

Sorry For late reply.

I check the time stamps for 1 hour but anyway the session expires after 14 minutes.
Is any possible way to prevent the session expires after 14 minutes or untill we close the browser.
Post Reply