ASP Access Quantity Statistics Code _ Application Tips
Source: Internet
Author: User
1. Building Database Tables Table name is online
Set the following fields
Id ' is used to record the Session.SessionID of each visit.
Name ' If it is a visitor, it is recorded as a visitor.
Online ' If is to visit each 0 if it is a member 1
DateTime ' Recent activity Time
Username ' Member's login username, the visitor is empty.
IP ' log access all logon IP
Head.asp ' writes the online number to the database table, which must be searched in each of the ASP pages for browsing.
<%
Set Rs=server.createobject ("ADODB. Recordset ")
If session ("username") = "" Then to determine that the user is not logged in
Sql= "SELECT * from online where id= '" ' &session.sessionid& "'" to determine whether this sessionid exists in the database table.
Rs. Open sql,conn,1,3
If Rs.eof then ' visitors for the first time browsing
Rs.addnew
RS ("id") =session.sessionid
RS ("name") = "Visitor"
RS ("online") =0 ' 0 means that the user is not logged in, 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 ' visitors not for the first time browsing
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 ") &" ' "' Judge Sess The Ionid or user name record already exists in the datasheet.
Rs. Open sql,conn,1,3
If Rs.eof Then
Rs.addnew ' Members enter the website for the first time (may login directly from the homepage of the website to enter the forum).
RS ("id") =session.sessionid
RS ("name") =session ("show") ' Write user nickname
RS ("username") =session ("username") ' Write to login user name
RS ("online") =1 ' means that the user has landed, 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//member is not the first time to browse the site, visitors login site.
RS ("name") =session ("show") updates user nicknames
RS ("username") =session ("username")
RS ("online") =1 ' means that the user has landed, 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 60 seconds without active visitors, time can adjust themselves.
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