且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何计算php中的登录用户数

更新时间:2023-12-04 08:11:22

4月22日下午3:05,snowi ... @ gmail .com写道:
On Apr 22, 3:05 pm, snowi...@gmail.com wrote:

大家好,

可以计算我登录我网站的用户数量吗?

任何帮助/代码赞赏,

craig
Hi all,
any way to count the number of users i have logged into my site?
any help/code appreciated,
craig



你真的有人用用户名/密码进行身份验证,

或者你只是想看看你的网站有多少人(独特用户)打了?b / b

Do you actually have people authenticating with usernames/passwords,
or are you just looking to see how many people (unique users) have hit
your site?


4月22日,20:09,通风< timgreg ... @ shieldinvestmentgroup.com写道:
On 22 Apr, 20:09, venti <timgreg...@shieldinvestmentgroup.comwrote:

4月22日下午3:05,snowi ... @ gmail.com写道:
On Apr 22, 3:05 pm, snowi...@gmail.com wrote:

大家好,

如何计算我登录我网站的用户数量? br />
任何帮助/代码赞赏,

craig
Hi all,
any way to count the number of users i have logged into my site?
any help/code appreciated,
craig



你真的有人用用户名/密码验证,

或者你只是想看看你的网站有多少人(独特用户)打了?


Do you actually have people authenticating with usernames/passwords,
or are you just looking to see how many people (unique users) have hit
your site?



我让他们先登录,由会话设置,所以我只想说

''有X用户登录''然后列出用户名。


那件事


干杯

I have them logging in first, set by a session, so I just want to say
''There are X users logged in'' and then list the usernames.

That kinda thing

Cheers


2008年4月22日星期二21:14:13 +0200,< sn ****** @ gmail.comwrote:
On Tue, 22 Apr 2008 21:14:13 +0200, <sn******@gmail.comwrote:

4月22日,20日:09,通风< timgreg ... @ shieldinvestmentgroup.comwrote:
On 22 Apr, 20:09, venti <timgreg...@shieldinvestmentgroup.comwrote:

> 4月22日下午3:05,snowi ... @ gmail.com写道:
>On Apr 22, 3:05 pm, snowi...@gmail.com wrote:

大家好,

如何计算我登录我网站的用户数量?

任何帮助/代码赞赏,

craig
Hi all,
any way to count the number of users i have logged into my site?
any help/code appreciated,
craig


你真的有人用用户名/密码验证,
或者你只是期待看看你的网站有多少人(独特用户)?


Do you actually have people authenticating with usernames/passwords,
or are you just looking to see how many people (unique users) have hit
your site?



我让他们先登录,由会话设置,所以我只想说

''有X用户登录''然后列出用户名。


I have them logging in first, set by a session, so I just want to say
''There are X users logged in'' and then list the usernames.



1)***使用数据库,有一个表active_users

2)每个请求都有一个会话&登录用户,使用带有时间戳(或日期时间)字段的用户ID插入记录

,使用当前

时间,或者使用当前

时间更新已经存在的记录该信息(如果

MySQL:ON DUPLICATE KEY UPDATE节省了很多麻烦)。

3)在检查活动用户时,删除active_users中的所有条目

表更新超过X分钟前(X是您的选择)。

4)显示活跃用户中的列表。


1如果您已经使用

session_set_save_handler()使用自定义处理程序在数据库中存储

会话,那么-3甚至更容易(也更可靠),但是如果你不要为其他

原因做这件事,因为只有活跃用户的脚本会有点过头。

-

Rik Wasmus

1) Preferably use a database, have a table active_users
2) On each request with a session & logged in user, either insert a record
with the user-id with a timestamp (or datetime) field, with the current
time, or update an allready existing record with that information (if
MySQL: ON DUPLICATE KEY UPDATE saves a lot of hassle).
3) On checking for active users, remove all entries from the active_users
table with updated more than X minutes ago (X is your choice).
4) Display the list in active users.

1-3 are even easier (and more reliable) if you''ve taken to storing
sessions in the database with a custom handler using
session_set_save_handler(), but if you don''t do this allready for other
reasons that would be a bit over the top for only an ''active users'' script.
--
Rik Wasmus