Skip to main content

Forced session time out in php - How to implement?


Forced session time out.

If you want to make sure that if a logged in user who is inactive on a web page for more than a specified time is forced to logout;

Here is the script to check for user inactivity and forced log out




session_start();

// set timeout period in 1200 seconds (20 minutes)
$inactive = 1200;

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

// your page content comes here

?>


Try this and put your suggestions

Read How to increase php session expiry time

Comments



Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog