Statistics
A statistical 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 <%response.write page3%> page per page display: [<a href=] dispcont.asp?pag=<%= Page3%>&pa=15 ">15], [<a href=" dispcont.asp?pag=<%=page3%>&pa=20 ">20] strip, [<a href=" Dispcont.asp?pag=<%=page3%>&pa=30 ">30] strip, [<a href=" dispcont.asp?pag=<%=page3%>&pa=40 " >40] Article
[<a href= "dispcont.asp" > Refresh]
<div align= "Left" >
<table border= "0" cellpadding= "0" style= "font-size:9pt" >
<tr><td> page </td><%page2=1
For I=1 to ZS step pages
If Page3=cstr (Page2) Then
%><TD >[<%response.write page2%>]</td>
<% Else%>
<TD ><a href= "Dispcont.asp?pag=<%response.write page2%>" >[<%response.write page2%>]</td >
<% End If
Page2=page2+1
Next
sn=pages* (page3-1) ' current record number = number of pages per page * Number of pages-per-page display
If Sn>zs then sn=0
Rs.move sn,1
' ********************************** above paragraph for paging
%> </tr></table>
</div> <table style= "font-size:9pt" width= "100%" bordercolorlight= "#000000" border= "1" bordercolordark= "# FFFFFF "bgcolor=" #A4D1E8 "cellspacing=" 0 "cellpadding=" 3 ">
<tr><td> number </td><td> Last visit home </td><td> last visit ip</td><td> home number </td ><td> First Visit Date </td></tr><%
For I=1 to pages
Response.Write "</tr>"
Response.Write "<td>" &rs ("ID") & "</td>"
Response.Write "<td>" &rs ("Dat") & "</td>"
Response.Write "<td>" &rs ("IP") & "</td>"
Response.Write "<td>" &rs ("CS") & "</td>"
Response.Write "<td>" &rs ("DAT1") & "</td>"
Response.Write "</tr>"
Rs.movenext
If Rs.eof then exit for
Next
Rs.close
%>
<tr><td> Total <%=zs%></td><td> number of visits 100 times <%=cs100%> </td><td> Total number of visits to 1:<%=cs1%></td><td> <%=csi%></td><td> visits today:<%=csdat1%> </td></tr>
</table>
' **************************** above is the complete pagination display all copies down is available. There is no consideration of a record.
You can change a little, add more features, OK, finally please pay attention to the website of Ah Yu: http://www.zydn.net
Here's a demo of this little program