How to expire PHP sessions after set a period of time
This post is about “How to expire PHP sessions after set a period of time”. In this post I’ll show you how to expire a user’s session after 6 minutes of inactivity.
<?php
session_start();
if(isset($_SESSION['login_user_mail_address']))
{
// set time-out period (in seconds)
$inactive = 600;
// check to see if $_SESSION["timeout"] is set
if (isset($_SESSION["timeout"])) {
// calculate the session's "time to live"
$sessionTTL = time() - $_SESSION["timeout"];
if ($sessionTTL > $inactive) {
session_destroy();
?>
// Page redirection
<script>window.location = 'logout.php';</script>
<?php
}
}
$_SESSION["timeout"] = time();
}
?>
session_start();
if(isset($_SESSION['login_user_mail_address']))
{
// set time-out period (in seconds)
$inactive = 600;
// check to see if $_SESSION["timeout"] is set
if (isset($_SESSION["timeout"])) {
// calculate the session's "time to live"
$sessionTTL = time() - $_SESSION["timeout"];
if ($sessionTTL > $inactive) {
session_destroy();
?>
// Page redirection
<script>window.location = 'logout.php';</script>
<?php
}
}
$_SESSION["timeout"] = time();
}
?>

Comments ( 0 )
Subscribe Latest Information
Categories
Most Popular Posts
How to Withdraw Money from ATM Machine 7steps 1127839 Views
How to Create Chat Application in Android Studio 144130 Views
How to Create a Shopping Cart Application in Android 105679 Views