I have a page that logs users out after 10 seconds of idling,but it does so without displaying a message and I need to refresh the page to show that I'm logged out. How do I display a message like "Logged out due to inactivity" with an okay button and when I click on it, it redirects back to index.php?
session_start();
$timeout = 10;
// Check if the timeout field exists.
if(isset($_SESSION['timeout'])) {
// See if the number of seconds since the last
// visit is larger than the timeout period.
$duration = time() - (int)$_SESSION['timeout'];
if($duration > $timeout) {
?>
<script type="text/javascript">
alert("Your session will expire soon!");
<?php header("location:../../index.php"); ?>
</script>
<?php
}
// Destroy the session and restart it.
session_destroy();
session_start();
}
// Update the timout field with the current time.
$_SESSION['timeout'] = time();