Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set session time out for fix time period in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 163
    Comment on it

    Hello Reader's,
    If you want to set session time out for fix time period in PHP use the below code.

    $page = $_SERVER['PHP_SELF'];
      $sec = "1";
      header("Refresh: $sec; url=$page");
    
      session_start();
      $now = time();
      if(!isset($_SESSION['start']))
      {
        $_SESSION['start'] = time(); // taking now page start time
      }
      $_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 30
    
      $outOfTime = $_SESSION['expire'] - $now;
      //print_r($_SESSION);
      echo $outOfTime;
      if($outOfTime<=0)
      {
          header("Location:http://www.google.com");
          session_destroy();
    
      }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: