I have created a Login page, amongst many others pages, which contains code to check the session. If the user doesn't have a session then all pages will reload and redirect to the logout page. This script is called every three seconds.
The code I've written is working fine but I want implement it another way. When the user logs out, all open tabs reload/refresh causing the user to be logged out. Is that possible?
sessioncheck.php:
<?php
session_start();
if(isset($_SESSION['username']) && $_SESSION['username'] != ''){
echo "true";
}
else {
echo "false";
}
?>
This code is in every page footer:
<script>
function gettatus(){
$.get("sessioncheck.php", function(data){
if(!data) {
window.location = "logout.php";
}
setTimeout(function(){
checkLoginStatus();
}, 3000);
});
}
$(document).ready(function(){
gettatus();
});
</script>