我有一个页面可以在闲置10秒后将用户注销,但是这样做没有显示消息,我需要刷新页面以显示我已经注销。如何显示"由于不活动而退出的消息"有一个好的按钮,当我点击它时,它重定向回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();