如何在mysql中获取当前登录的用户? [英] how to get currently logged users in mysql ?

查看:72
本文介绍了如何在mysql中获取当前登录的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的网站上获取当前登录的用户.我有一个用于维护用户的 mysql 表.

how to get currently logged users in my website. I have a mysql table for maintain users.

我不知道如何显示已登录的姓名.

I don't know how to display names who are logged in.

推荐答案

不要像其他人建议的那样使用 isOnline 字段.而是使用 lastSeen 字段.您可以在该字段中放置时间戳并在每次页面查看时更新它.

Don't use a isOnline field as others suggested. Instead use a lastSeen field. You can put a timestamp in that field and update it either on every page view.

如果你想在你的系统上轻松一点,你可以每隔几分钟更新一次(在用户会话中使用一个变量 $lastUpdate 包含 lastSeen<的最后一次更新的时间戳/代码>).

If you want to go easy on your system, you can update every couple of minutes (with a variable $lastUpdate in the user session containing the timestamp of the last update of lastSeen).

要查找在线"用户,您可以选择过去 X 分钟内lastSeen 的所有用户,例如 10 分钟.

To find "online" users, you can select all the users that were lastSeen in the last X minutes, for instance 10 minutes.

您无法知道在线用户的确切数量,因为您无法知道用户是在查看您的页面还是他/她已经关闭了它.无论如何,像这样的解决方案是一个很好的近似.

You can't know an exact number of online users, because you can't know if an user is looking at your page or he/she has already closed it. Anyway, a solution like this one is a good approximation.

每小时或每天,根据您有多少访问者,您可以运行一个过程来删除旧条目.

Every hour or every day, depending on how many visitors you have, you can run a process to delete old entries.

这篇关于如何在mysql中获取当前登录的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆