1. Create a database table Table Name: Online
Set the following fields
Id' is used to record the session. sessionid of each access.
Name' if it is a visitor, it is recorded as a visitor.
Online, if the access is 0, if the access is 1
Datetime 'latest activity time
Username' indicates the username of the member. The guest is empty.
IP address 'record logon IP addresses for all accesses
Head. asp: the number of online users written to the database table. This page must be searched into every ASP page used to browse.
<%
Set rs = server. Createobject ("ADODB. recordset ")
If SESSION ("username") = "" then determines that the user is not logged on
SQL = "select * from online where id = '" & session. sessionid & "'" 'determines whether the sessionid exists in the Database Table.
Rs. Open SQL, Conn, 1, 3
If Rs. EOF then' the visitor browsed for the first time
Rs. addnew
RS ("ID") = session. sessionid
RS ("name") = "Tourists"
RS ("online") = 0' 0 indicates that the user has not logged in. It is a tourist identity.
RS ("datetime") = now ()
Userip = request. servervariables ("http_x_forwarded_for ")
If userip = "" then
Userip = request. servervariables ("remote_addr ")
End if
RS ("ip") = userip
Else 'guest not the first visit
RS ("datetime") = now () 'update activity time
Rs. Update
Rs. Close
End if
Else
SQL = "select * from online where id = '" & session. sessionid & "'or admin ='" & SESSION ("username") & "'"' determines that the sessionid or user name record already exists in the data table.
Rs. Open SQL, Conn, 1, 3
If Rs. EOF then
Rs. addnew' members log on to the website for the first time (they may log on to the forum directly from the homepage ).
RS ("ID") = session. sessionid
RS ("name") = SESSION ("show") 'write user nickname
RS ("username") = SESSION ("username") 'write the Login User Name
RS ("online") = 1' indicates that the user has logged on and is a member.
RS ("datetime") = now () 'sets the current system time to the user's logon time
Userip = request. servervariables ("http_x_forwarded_for ")
If userip = "" then
Userip = request. servervariables ("remote_addr ")
End if
RS ("ip") = userip
Else // the member does not browse the website for the first time and the visitor logs on to the website.
RS ("name") = SESSION ("show") update user nickname
RS ("username") = SESSION ("username ")
RS ("online") = 1' indicates that the user has logged on and is a member.
RS ("datetime") = now ()
End if
Rs. Update
Rs. Close
End if
Set rs = nothing
%>
Conn.exe cute ("delete from online where datediff ('s ', datetime, now ()> 60")' deletes a visitor who has no activity for 60 seconds. You can adjust the time by yourself.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service