Web Development Tips and Tricks

Web Development Tips and Tricks

Thursday, March 17, 2011

Auto Logout in php

Copy and paste this code on youre page
you can change time as your need i take 60 sec .
< ? php
session_start();

// set timeout period in seconds
$inactive = 60;

// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{
// go to login page when idle
session_destroy(); header("Location: logout.php");
}
}?>

No comments:

Post a Comment