A statistical solution to current online users

xiaoxiao2021-03-06  40

When making an online communication site, there is a problem that I have a headache. It is about the problem of real-time statistics online users. Customer requirements: statistics, current online number, number of tourists, number of members, online users, including tourists, members, and management Revenner (if you are a tourist, you automatically generate the idler ID, if it is a member, the member name is displayed). Because it requires real-time, first I will drop the idea pass from Global.asa. The key to the problem is how to determine how the user has left, and how to execute a file or a function when the user leaves. After discussing some friends on the Internet, this problem finally solved. The solution is: writing a general page, so-called general page, each page in the application contains this page, for example: header.asp, in this page, write a code with XMLHTTP, this code is A request is sent to the server every 10 seconds or 20 seconds to update the current user's online time and delete the online time of more than a certain period of time, so that the online user record in the database maintains a certain real-time.

The main implementation method is: New a database, field name is: ID (character), Name, user (number) Tt (date), admin (permission code, 0-ordinary user, 1-administrator) table name : Online header.asp ↓ ============================================== ================= <% ... if session ("s_in") <> 1 and session ("s_name") = "" "" if the user is the first Login RS.Open "Select * from online", conn, 3, 3 rs.addnew = session.SessionID RS ("Name") = "Visitor" & session.SessionID RS ("User" ) = 0 '0 indicates that the user is not logged in, it is a tourist identity rs ("tt") = now rs.Update rclose session ("s_in") = 1' Setting the user's information has been deposited into the database, indicating already online END IF If session ("s_name") <> "" "" "SELECT *" SELECT * from ONLINE WHERE ID = '"" & session.Session) or "" ") = session (" s_name ") = session (" s_admin ") 'Update the user's name is the member name RS (" User ") = 1' indicates that the user has logged in and is the member identity RS ("TT") = now 'Set the current system time to the user's login time update rs.closend if ...%> ... ...