Make a simple website statistics
Design ideas: Trigger the server sessionid to record the user's login status when using the user web page request. Since the most request activity of each webpage is the confon.asp file, we use this file to do online users' information processing. When the user is 20 minutes, the user When there is no web page request, remove this user.
1. Data table: We add two tables to the database
LINE table: Sessionid character type 20 -bit to record the unique mark of the customer web page request
Userdate Date Time Type for recording the time of the customer's last web page request
ID automatic number type
You can also record other information in this table, such as accounts, IP and other information
Count table: Userdate Date time type is used to record the date of the day
Count digital type is used to record website click volume
TODAY digital type is used to record today's access volume
MAX digital type is used to record the maximum visits of the day
In this table, because there is only one record, it is not necessary to use the ID field, but retaining the ID field is a good habit
2. Use con.asp to process the LINE table
(1) Connect the database
dim conn
dim connstr
dim db
db = "date/date.mdb"
Set conn = server.createObject ("Adodb.connection")
Connstr = "Provider = Microsoft.jet.OLEDB.4.0; Data Source =" & Server.MAPPATH ("" & DB & "")
conn.open connstr
(2) Clear timeout records
conn.execute ("Delete from line where datediff (" "s", userdate, now ())> = 1200 ")
(3) Record customer information to LINE table and perform statistical processing of site
dim SQL, SQL1, RS, RS1
Set rs = server.createObject ("Adodb.oldSet")
sql = "select * from line where [sessionid] =" "" & session.SessionID & "" "determine whether the customer's initial web page request
RS.Oopen SQL, CONN, 1,3
If not rs.eof then "If it is the original web page request, record customer information, otherwise it will only change the request time
RS ("Userdate") = Now ()
else
Set rs1 = Server.CreateObject ("Adodb.oldset") "
sql1 = "select * from [count]"
RS1.OPEN SQL1, Conn, 1,3
if rs.eof then "If there is no record in the table, initialize this table
rs.addnew
RS ("Count") = 1
rs ("max") = 1
RS ("Today") = 1
RS ("Userdate") = Date ()
else
RS1 ("Count") = RS1 ("Count") 1 "website clicks count count
If RS1 ("Userdate") = Date () then "If the system date is the same as the last date of the data record, add 1 visits 1
RS1 ("TODAY") = RS1 ("TODAY") 1
If ElSe 'Different, set the daily access volume 1, and change the data record date to the server date
RS1 ("Today") = 1
RS1 ("userdate") = date ()
end if
RS1.UPDATE
If RS1 ("Max") <= RS1 ("TODAY") then 'If the statistics of the day exceeded the maximum daily visits, update the maximum daily visits
RS1 ("Max") = RS1 ("TODAY")
end if
end if
RS1.UPDATE
RS1.Close
set rs1 = nothing
RS.Addnew "The following is the user's information
rs ("sessionid") = session.Sessionid "to write sessionid into the data table
rs ("userdate") = Now () write the system date to the data table
end if
rs.update
RS.Close
set rs = Nothing
The above processing is just ready for statistics. The code used for website statistics is as follows. We use line.asp as the file name
<!-#Include file = "conn.asp "->
<% Dim Count, TODAY, MAX, LINE
Set rs = server.createObject ("Adodb.oldSet")
sql = "select * from [count]" "
RS.Oopen SQL, CONN, 1,1
TODAY = RS ("TODAY")
Count = RS ("Count")
max = RS ("Max")
RS.Close
set rs = Nothing
Set rs = server.createObject ("Adodb.oldSet")
sql = "select count (*) from line"
RS.Oopen SQL, CONN, 1,1
LINE = RS (0)
RS.Close
set rs = Nothing
%>
We have prepared the website statistics above, and put them in the variable count, today, max, line. In the .ASP webpage, we can use response.write to output and use include to quote, but in the HTML documentation, it must No, so we have to use the following sentences to output statistical content:
document.write ("Website visits: <%= Count%> People <br>")
document.write ("Today: <%= TODAY%> People visited this site <br>")
document.write ("The highest daily visits of this site: <%= max%> people <br>")
document.write ("Current online: <%= LINE%> People")
We use <script src = "line.asp"> </script> to quote this file