-5

If a person idles for 10 minutes then I want the page expired -> user has to login again to continue.

Ankit Sharma
  • 398
  • 1
  • 7
  • 19

2 Answers2

2
ini_set("session.gc_maxlifetime","600");
session_start(); 
m4t1t0
  • 5,669
  • 3
  • 22
  • 30
0
session_start();
if( time() - $_SESSION['login_time'] > 600)
{
    header("Location:login.php");
}

This will check if the session has been running for more than 600 seconds (10 minutes).

Of course first you have to store:

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

when the session is created.

nowhere
  • 1,558
  • 1
  • 12
  • 31
  • But Ankit wants session to expire **when user is idle** for 10 mins and not after 10 mins of login. I guess, if your answer is implemented then user will be redirected to login page after 10 mins, no matter user is active or idle. – Bhavik Shah Feb 06 '13 at 09:36
  • mmm yes the title fooled me. In this case i suppose jquery is the only option http://paulirish.com/2009/jquery-idletimer-plugin/ – nowhere Feb 06 '13 at 09:39