Session Timeout


/ Published in: PHP
Save to your folder(s)

This is a neat little process for setting a timer and ending a session - change time to reflect minutes for timeout, change redirect to your logout page


Copy this code and paste it in your HTML
  1. // set timeout period in seconds (600 = 10 minutes)
  2. $inactive = 600;
  3. // check to see if $_SESSION['timeout'] is set
  4. if(isset($_SESSION['timeout']) ) {
  5. $session_life = time() - $_SESSION['timeout'];
  6. if($session_life > $inactive)
  7. { session_destroy(); header("Location: logoutpage.php"); }
  8. }
  9. $_SESSION['timeout'] = time()

URL: http://www.daniweb.com/web-development/php/threads/124500/session-time-out-in-php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.