i want user to automatically logout if they inactive for certain time, so im following some tutorial, with help of ajax inactive user are logout automatically. but while using ajax im getting 404 status error. after user is login they sent ot index page.
<?php
require("includes/user_auth.php");
echo "Hello";
?>
<h1>time <?php echo $_SESSION['LAST_ACTIVE_TIME']; ?></h1>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
//check every 2sec for use activities
<script>
setInterval(function(){
check_user();
},2000);
function check_user(){
jQuery.ajax({
url:'user_auth.php',
type:'post',
data:'type=ajax',
success:function(result){
if(result=='logout'){
window.location.href='logout.php';
}
}
});
}
</script>
checking for user time for their activities
<?php
session_start();
if(isset($_POST['type']) && $_POST['type']=='ajax'){
if((time()-$_SESSION['LAST_ACTIVE_TIME'])>120){
echo "logout";
}
}else{
if(isset($_SESSION['LAST_ACTIVE_TIME'])){
if((time()-$_SESSION['LAST_ACTIVE_TIME'])>120){
header('location:../logout.php');
die();
}
}
$_SESSION['LAST_ACTIVE_TIME']=time();
if(!isset($_SESSION['IS_LOGIN'])){
header('location:index.php');
die();
}
}
?>
but its not working…
what could possible reason…