Detect online users?

前端 未结 4 956
野趣味
野趣味 2020-12-08 22:45

I\'m not sure what would be the easiest way to do this. I need to be able to detect what users are online on my website. So when people are viewing a thread or something it

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 23:34

    • have a MySQL database with a user table
    • have a column in that user table which saves the "last seen"-time
    • update that column on every page request
    • when checking for online or offline, check if current time minus "last seen"-time is greater than some treshold you like

    Edit: You could optionally make a javascript "ping" the server (request an empty page) every two minutes or so if you want people idling with your Website open to be displayed as online, too.

提交回复
热议问题