开发者

Is this the best way to update user status?

开发者 https://www.devze.com 2023-02-15 10:27 出处:网络
Status as in online/offline.. When a user enters onto a page, it records the current time and puts it in the database.. if 5 minutes开发者_JAVA百科 passes since their last action, it shows them as of

Status as in online/offline..

When a user enters onto a page, it records the current time and puts it in the database.. if 5 minutes开发者_JAVA百科 passes since their last action, it shows them as offline?


You can use JavaScript to time the five minutes, then use AJAX to call a PHP script that updates the database.

window.onLoad = function(){
  setTimeout(UpdateDB,1000*60*5);
}

function UpdateDB(){
  // AJAX call...
}


This would be a good way to start. You can easily check the period of inactivity.


It would be relatively simple for you to set up an AJAX ping to your server on a long interval~ so that as long as the user's browser has your site loaded, it's still pinging it's status as online.

0

精彩评论

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