0

I'm trying session expire when computer goes sleep mode after 1min. How i need to implement this one.

 <?php
    include('config.php');
    session_start();
    $myusername=$_SESSION['myusername'];
    $ses_sql=mysql_query("select nocname from nocusers where nocname='$myusername' ");
    $row=mysql_fetch_array($ses_sql);
    $login_session=$row['nocname'];
    if(!isset($login_session))
    {
    header("Location:login.php");
   }
?>
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
marvan
  • 31
  • 3
  • 13
  • possible duplicate of [how to logout session if user idle in php](http://stackoverflow.com/questions/3453831/how-to-logout-session-if-user-idle-in-php) – Amal Murali Feb 17 '14 at 12:16

1 Answers1

1

first of all you have to change your session timeout for1 min = 60seconds like this

ini_set('session.gc_maxlifetime', 60);

now you can check the session value each time on your page when load. if activity not happen within 1 min session will expire and you went to logout like this

 <?php
    include('config.php');
    session_start();

   if(isset($_SESSION['myusername']))
   {
      $myusername=$_SESSION['myusername'];
      $ses_sql=mysql_query("select nocname from nocusers where nocname='$myusername' LIMIT 1 ");
      if($row=mysql_fetch_array($ses_sql))
      {
          $_SESSION['myusername'] = $row['nocname'];
      }  
      else
      {
         // logout here
      }

   }
   else
   {
       // logout here
   }
?>

UPDATE 2:

you can also store a last activity time in your database respect to each user. and update it every time on top of each page. before it check that last updated time is less than 1 minute if yes it means no activity by this user greater than 1 minute. logout it.

Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
  • Well. Thanks Shrma, But I need session expire Depend computer activity not for particular website. I made this one for employees. – marvan Feb 17 '14 at 12:41