Free2Code
 
Time: 2008-11-21, 08:29am
session timeout
Subject: session timeout  ·  Posted: 2007-12-27, 05:46pm
Rank: ? (2)
Member #: 29702
Hi,

Am new to php... i created login form with session... I wish to do that if user didnt do anything in that form for 5 min means it should go to login page once again...

<?php

session_start();

if(session_is_registered('email'))
{
echo 'Login successful';

}
else
{
header("location:main.php");
}

?>

this is my session creation coding.. wat i have to do after this to achieve above said needs.....

Anybody help me to do this...

Thanks,


 
  Reply to this ·  Post link ·  Top
Subject: Re: session timeout  ·  Posted: 2007-12-29, 11:37am
Rank: ? (767)
Member #: 11085
I would suggest you use cookies instead, as they have a life parameter.

What you want to do is, I believe, possible with sessions, but I don't recall how to set a timeout on them (if I ever knew).

- relpats_eht
 
  Reply to this ·  Post link ·  Top
Subject: Re: session timeout  ·  Posted: 2007-12-31, 04:45am
Rank: ? (4821)
Member #: 3416
there’s a timeout for sessions, but if you’re on shared hosting you probably don’t have access to change it. what i do is store in the session the last time a page was loaded, with something like this:

$_SESSION['lastload'] = time();

then if you want sessions to only be good for 5 minutes since the last page load, that’s 300 seconds, so also check this when you check if there’s a valid login session:

if(time() - $_SESSION['lastload'] > 300)
// destroy session and go to the login page

if you want to automatically redirect the user to the login page after 5 minutes instead of waiting for them to request a different page (or submit your form), you can use either javascript or the refresh header. i don’t recommend doing that sort of thing though as it is very annoying to users if a page they had open is no longer open and they didn’t do anything to make that happen.

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: session timeout  ·  Posted: 2008-01-18, 06:44pm
Rank: ? (2)
Member #: 29702
I updated my code as u said but session has not get destroyed.. I wish it to destroy and should automatically redirect to another page after 5 min...

It will be very helpful if anybody give idea to do like this.....

 
  Reply to this ·  Post link ·  Top
Subject: Re: session timeout  ·  Posted: 2008-01-19, 03:53am
Rank: ? (767)
Member #: 11085
Ah, you want it to automatically redirect on timeout.

In that case, you will need some javascript which checks that cookie from time to time to see if it has expired and, if so, redirects.

- relpats_eht
 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons