Statistical method of online number.

zhaozj2021-02-16  97

/ ******* 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

The last event time is updated to: $ SQL = "Update User_Table Set LastAVTIVE = (Time () - 300) Where user_name = 'user_name" "; changed to 5 minutes earlier than the current time. In ordering to log in to the user when the user logs out, the user cannot log in.

Then refresh the page through the page Meta element, update the user record: $ sql = "Update user_table set lastactive = time () where user_name = 'user_name" "

It's basically completed, add another user login: 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 once, add 60. Execute the query, if you get the result, it is judged that he is online and gives a tip: You cannot log in twice at the same time. And exit. If there is no result, log in, and use the session to register. 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-11751.html

New Post(0)