Statistics An example of how visitors can number, record access times, IP, and time.
I made a website, www.zydn.net of course, like everyone else, also put a counter in the top, every day to see the counter are constantly turned, the heart is very happy, but then I think, in the end who saw my website ah? A new friend or an old friend? I don't know how many times they've been here, I also want to give them a number, so I applied for free statistics, but for a change of N are not satisfied, alas, it seems, only their hands to have enough to do, said dry, level smelly, but also hope that the master jokes, not visit the advice.
I use the Access library as an example, in fact, with the SQL Server library, just change the statement of the link library,
The library structure is as follows
Library filename: CONT. ASP was originally Cont.mdb but after construction, the extension was changed to ASP, in case the library was downloaded.
Table Name: Tab
Field Name Data type description
ID AutoNumber number of Visitors
IP text is used to record the IP of a visitor
DAT1 date time to record the last visit of the visitor
DAT date time is used to record the time of the first visit of a visitor
CS number, Integer used to record the number of visitors visited
The program is simple, only two files, dispcont.asp to display statistical results, contpage.asp for statistical information,
First look at the contpage.asp is the first statistics, the code is as follows:
<%
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("cont.asp") + ";D efaultdir=;D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open CONNSTR ' * * * The above statement is used to connect the library, cont.asp is the library file name.
Keren=request.cookies ("Keren") ' reads Cookies,cookies's name: "Keren", haha. Ah Yu's e-literature stinks, only know how to use pinyin.
If keren= "" Then ' Judge Cookees is not empty, if it is empty, then must be new friends, otherwise it is an old friend.
Sql= "SELECT * from tab where Id=-1"
Set Rs=server.createobject ("ADODB. Recordset ")
Rs. Open Sql,conn, 1, 3
Rs.addnew ' If it's a new visitor, add a record in the library.
RS ("cs") =1 ' write Down access times 1
RS ("IP") =request.servervariables ("remote_addr") ' Notes IP,
RS ("Dat") =now ' notes the current date time,
RS ("DAT1") =date ' write down the current date, later used for the first visit date,
Response.Cookies ("Keren") =rs ("id") ' writes a cookie, and the content is the same as the ID.
Response.Cookies ("Keren"). expires=date+365 ' Set the effective date for cookies from now on, 365 days,
Else ' is the way to deal with new friends, what about old friends? Look at the following:
Sql= "SELECT * from tab where id=" &keren "to the library to find out the records of our old friends.
Set Rs=server.createobject ("ADODB. Recordset ")
Rs. Open Sql,conn, 1, 3
RS ("CS") =rs ("cs") +1 ' Okay, here we go, add 1 to the number of visits.
RS ("IP") =request.servervariables ("remote_addr") ' See how much of his IP is, write it down.
RS ("Dat") =now ' write down the current time, which is the time of the last visit,
Response.Cookies ("Keren") =rs ("id") ' Write cookies again, I do not know if this is superfluous, did not try.
Response.Cookies ("Keren"). expires=date+365 ' Set the cookie expiration time, lest I should not recognize him in a year.
End If
Rs.update ' should write down, update the library.
Rs.close ' closes the Recordset object.
Set conn=nothing ' Release Conn, I still think connection to follow with Guancai to, put to the session I think the most undesirable. 4
%>
Well, the record is done, there are more than 20 lines of code, very simple a small program, but I think, the master must have a good idea, there are clever friends do not forget to teach Ayu,
The program is written, how to put it on the page? Very simple, on the home page to find a place, plus this line of code: on the line.
The next step is to show the records, this can be done better than the people of the many, but still come to an ugly.
File name: dispcont.asp, see Code:
<%
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("cont.asp") + ";D efaultdir=;D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open CONNSTR ' * * * The above statement is used to connect the library, cont.asp is the library file name.
Page3=request ("Pag")
If page3= "" Then Page3=session ("Contpag") ' page number, current paging
If page3= "" Then page3= "1"
Pa=request ("Pa")
If Pa= "" Then Pa=session ("Contpa") ' Show number per page
If Pa= "" then pa=15 "default per page display 15, can be arbitrarily changed
Session ("Contpag") =page3
Session ("CONTPA") =pa
Pages=pa ' Display quantity per page *************** above a program for paging functionality
Sql= "SELECT * from tab order By-dat,-id"
Dim rs
Set rs=server.createobject ("ADODB. RecordSet ")
Rs. Open sql,conn,1,1
Csi=0
Cs1=0
Cs100=0
Csdat1=0
Do as not rs.eof
CSI=CSI+RS ("CS")
If RS ("CS") =1 then cs1=cs1+1
If RS ("CS") >=100 then cs100+1
If DateValue (rs ("Dat")) =date Then
Csdat1=csdat1+1
End If
Rs.movenext
Loop
Zs=rs. RECORDCOUNT
' *****************************************************8 the following procedure for paging display
%>
<title> Excel Computer Statistics </title>
<body style= "font-size:9pt" bgcolor= "#D8EDF8" >
A total of <%response.write zs%> Records, now the <%response.write pag