ASP creates access statistics code, Example 1. Create database table
The table name is online
Set the following fields
id 'session.sessionid used to record each access
name 'If it is a visitor, it will be recorded as a visitor.
online 'if it is a visitor, it is 0, if it is a member, it is 1
datetime 'Latest activity time
username 'Member's login username, guest is empty.
ip 'Record the login IP of the visit
head.asp 'Write the number of people online to the database table. This page must be included in every ASP page used to browse.
<%
set rs=Server.CreateObject(ADODB.Recordset)
if session(username)= then determines that the user is not logged in
sql=select * from online where id='&session.sessionid&' 'Determine whether this sessionid exists in the database table.
rs.Open sql,Conn,1,3
if rs.eof then 'Visitor's first visit
rs.addnew
rs(id)=session.sessionID
rs(name)=visitor
rs(online)=0 '0 means the user is not logged in and is a visitor.
rs(datetime)=now()
userip = Request.ServerVariables(HTTP_X_FORWARDED_FOR)
If userip = Then
userip= Request.ServerVariables(REMOTE_ADDR)
end if
rs(ip)=userip
else 'Visitor is not browsing for the first time
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)&' 'Determine whether the sessionid or username record already exists in the data table.
rs.Open sql,Conn,1,3
if rs.eof then
rs.addnew 'The member enters the website for the first time (may log in directly from the website homepage to enter the forum).
rs(id)=session.sessionID
rs(name)=session(show) 'Write user nickname
rs(username)=session(username) 'Write login username
rs(online)=1 'Indicates that the user has logged in and is a member
rs(datetime)=now() 'Set the current system time to the user's login time
userip = Request.ServerVariables(HTTP_X_FORWARDED_FOR)
If userip = Then
userip= Request.ServerVariables(REMOTE_ADDR)
end if
rs(ip)=userip
else //This is not the first time the member browses the website, and the visitor logs in to the website.
rs(name)=session(show) updates user nickname
rs(username)=session(username)
rs(online)=1 'Indicates that the user has logged in and is a member
rs(datetime)=now()
end if
rs.update
rs.close
end if
set rs=nothing
%>
conn.execute(delete from online where datediff('s',datetime,now())>60) 'Delete visitors who have been inactive for 60 seconds. The time can be adjusted by yourself.