How to handle user online status when he/she close the browser?

后端 未结 5 1020
自闭症患者
自闭症患者 2021-01-06 01:47

I am having table to track user online status by setting \'is_online\' field to 1. Now User get logged in the site and shut down his/her system or power down at that time he

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-06 02:11

    You can use jquery to update your site each X time, so a function is executed each 10 seconds, as following code:

    function updateTheBBDD(){
        ... calling mysql_connect -> mysql_insert -> mysql_close
    }
    
    setInterval("updateTheBBDD()",10000);
    

    Also, when painting the user status monitor instead of consulting the BD and:

    1->green
    0->red
    

    You should:

    actual - time > 10  ---> red
    actual - time <= 10 ---> green
    

提交回复
热议问题