1. Create a database table
The table name is 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 it is visiting, each is 0 if it is a member 1
datetime'Latest Event
username' member's login username, the visitor is empty.
ip'record access to all login IP
head.asp' writes the number of people online to the database table, and the page must be searched into each page used to browse the ASP.
<%
setrs=Server.CreateObject("ADODB.Recordset")
ifsession("username")=""then determines that the user is not logged in
sql="select*fromlinewhereid='"&session.sessionid&"'"'"' determine whether this sessionid exists in the database table.
rs.Opensql,Conn,1,3
ifrs.eofthen'Visitor's First View
rs.addnew
rs("id")=session.sessionID
rs("name")="Guest"
rs("online")=0'0 means that the user is not logged in and is the identity of the tourist
rs("datetime")=now()
userip=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
Ifuserip=""Then
userip=Request.ServerVariables("REMOTE_ADDR")
endif
rs("ip")=userip
else'Not the first time visitors browse
rs("datetime")=now()'Update activity time
rs.update
rs.close
endif
else
sql="select*fromlinewhereid='"&session.sessionID&"'oradmin='"&session("username")&"'"'"'Just determine that the sessionid or username record already exists in the data table.
rs.Opensql,Conn,1,3
ifrs.eofthen
rs.addnew' members enter the website for the first time (maybe log in directly from the homepage of the website to enter the forum).
rs("id")=session.sessionID
rs("name")=session("show")'Write to user nickname
rs("username")=session("username")'Write to login username
rs("online")=1' means that the user has logged in and is a member
rs("datetime")=now()'Set the current system time as the user's login time
userip=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
Ifuserip=""Then
userip=Request.ServerVariables("REMOTE_ADDR")
endif
rs("ip")=userip
else//A member is not browsing the website for the first time, and the visitor logs into the website.
rs("name")=session("show") update user nickname