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

后端 未结 5 968
自闭症患者
自闭症患者 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:08

    you can't. HTTP closes the connection once the page has been delivered. On the server side alone all you could do is checking if a user has requested a page within a certain amount of time.

    JavaScript might be your friend. You could use it to create a ping to a php script which then updates the last request timestamp. Once there is no more pinging, the user is gone and you'd know.

    If you have trouble with javaScript, a good point to start would be here: http://www.w3schools.com/JS/

    You might want to focus on the AJAX and HTTP request stuff.

    cu Roman

提交回复
热议问题