如何找出创建的会话总数,即已登录的用户数? [英] How do I find out total number of sessions created i.e. number of logged in users?

查看:113
本文介绍了如何找出创建的会话总数,即已登录的用户数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个简单的基于成员资格的网站,用户可以登录并拥有自己的个人资料.我希望能够在任何给定的时间点告诉我当前有多少用户或哪些用户登录了我的网站.

Hi guys I have a simple membership based website where users log in and have their own profiles. I woudl like to be able to tell at any given point in time how many users or rather which users are currently logged into my website.

它是一个基于php的简单的基于成员资格的系统.我理解它的一种方法是在数据库中创建一个表,并在其中存储登录详细信息和会话数据,但是可以通过其他方法来完成,即无论如何找出已经启动了多少会话以及所有唯一用户在线.

Its a simple membership based system in php. One way I uderstand it creating a table in a db and storing login details there and session data as well but can this be done in some other way i.e. anyway to find out how many sessions have been started and all the unique users online.

推荐答案

执行此操作的最佳方法是记录每个用户的lastActivityTime.当他们访问页面时,将时间记录在他们的数据库记录中.完成此操作后,运行一个简单的查询以计算所有距Current Time少于5分钟的lastActivityTime记录.

The best way to do this is record the lastActivityTime for each user. When they access a page, log the time in their db-record. Once you're doing that, run a simple query to count all records that have a lastActivityTime less than 5 minutes from the Current Time.

因此,您不是在询问最近有多少用户登录",而是在询问最近有多少用户处于活动状态".

So rather than asking "how many users are logged in," you're asking "how many users were recently active."

这篇关于如何找出创建的会话总数,即已登录的用户数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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