开发者

read data returned from jquery .post

I have a page that I want redirected to the login page if a user is inactive for 1/2 hour. I am new to jQuery and it has taken me awhile to get this far. So basically the user logs in they are redirected to the home page. I have jQuery running on the home page that posts to the check_time.php page every 10 seconds. if they have been inactive for more than a 1/2 hour, then session is destroyed and they get redirected to the login page. I have everything working except checking the value of the "data" that is returned from the check_time.php page.

here is the code on the home page.

ini_set('session.gc_maxlifetime',1800);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1); 
session_start();
if($_SESSION['admin_login'] != $password){
    header('Location: index.php'); 
    exit();
}
if(isset($_SESSION['last_act开发者_开发技巧ivity']) && (time()-$_SESSION['last_activity'] >1800)){
// last request was more than 30 minates ago
session_destroy();   // destroy session data in storage
session_unset();     // unset $_SESSION variable for the runtime
    header('Location: index.php'); 
    exit();
}
$_SESSION['last_activity'] = time(); // update last activity time stamp
?>


<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">     

function timedCount(){        
    $.ajax({
      type: 'POST',
      url: "check_time.php",
      success: function(data){
        if (data == "LOGOUT") {
    window.location = 'index.php';
        }
}
});
setTimeout("timedCount()",10000);
 };

</script>

this is the code on the check_time.php

<?php

  session_start();
    if (isset($_SESSION['last_activity'])){
        if(time() - $_SESSION['last_activity'] > 1800){
            session_unset();
            session_destroy();
            echo "LOGOUT";  
        }
    }else{
        echo "LOGOUT";
    }
?>

I asked this same question last week I wanted to post my latest code so I stated a new question. I really greatly appreciate your help!!!!!


try :

if (jQuery.trim(data) == "LOGOUT")
{
   ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜