Statistical method of online number

zhaozj2021-02-16  95

Statistical method of online number

This article is reproduced from: http://blog.9cbs.net/52juanjuan/archive/2004/07/30/online.aspx

/ ******* Author: Fibona Xiong Xiangzhong

******** DATE: 2004-7-30

******** Function: Online number statistics: * /

Write more detailed, but I will give you a more useful thinking (a way):

First add a field in the user table in the database, and the user's last event time is like a LastActive field. Some are stored in Unix time form.

It is judged that the user online can be used if the last activity time is within two minutes of the current activity time. $ SQL = "SELECT Count (*) AS CNT from User_Table Where Lastactive 120

User's final activity time is updated to:? $ Sql ​​= "Update user_table set LastAVTIVE = (Time () - 300) Where user_name = 'user_name" "; changed to become 5 minutes earlier than the current time In order for the user to log in to the case where the user can log in and cannot log in.

Then refresh the page through the page's meta element, update the user record:? $ Sql ​​= "Update user_table set lastactive = time () where user_name = 'user_name" "

It's basically completed, add a user login to the judgment:? If he is online, no longer login and give friendly tips:? $ Sql ​​= "select * from user_table where user_name = 'user_name" and lastactive 60> = Time (); // Because it is one minute to update it, add 60. • Execute the query, if the result is determined to be a online and give a prompt:? At the same time, you cannot log in twice. And exit. • Log in without results, and registration with session, etc. This is relatively simple.

A complete online number statistics are completed.

Please complete the code of the program yourself. If you don't understand, please contact QQ: 185923958.

转载请注明原文地址:https://www.9cbs.com/read-11747.html

New Post(0)