Simple ASP Statistics Production examples _ Application skills

Source: Internet
Author: User
Tags ip number servervariables table name

I made a website, 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 for the n are not satisfied, alas, it seems, only their hands to be able to have enough, said dry, but also hope that the master jokes, do not visit the advice.
I use the ACCESS Library As an example, in fact, with the SQL Server library also just change the statement of the link library,
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 visitor number
IP text to record the IP
DAT1 date time of the visitor's last visit
Dat date time is used to record the time of the first visit of the visitor br> CS number, integer used to record the number of visits to visitors
The program is very simple, only two files, dispcont.asp used to display statistical results, contpage.asp for statistics,
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") ' Write down IP, rs ("Dat") =now ' write down the current date time, RS ("dat1") =
Date ' notes 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 valid date for cookies from now, 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 our old friend's record
set Rs=server.createobject (" ADODB. ") Recordset ")
Rs. Open Sql,conn, 1, 3
RS ("cs") =rs ("cs") +1 ' OK, found, add the number of accesses 1
rs ("IP") =request.servervariables ("remote_addr") ' Take a look at his IP number and write it down.
rs ("Dat") =now ' write down the current time, that is, the time of the last visit,
response.cookies ("Keren") =rs ("id") "to the cookies, 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 ' write down all the notes, 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.
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: 〈img src= "contpage.asp" width= "0" height= "0" 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") ' pagination, current paging if page3= "" Then page3= "1" pa=request ("Pa") if p A= "" "Then Pa=session (" Contpa ") ' Show number of If Pa= '" then pa=15 ' default per page display 15, can be arbitrarily changed session ("Contpag") =page3 session ("CONTPA") =pa p Ages=pa ' per page display quantity *************** The above section of the program is used to implement 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, 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 End If Csdat1=csdat1+1 loop rs.movenext. RECORDCOUNT ' *****************************************************8 The following procedure is used for paging display%〉〈head〉〈title〉 excellent computer statistics 〈/title〉〈/ Head〉〈body style= "font-size:9pt" bgcolor= "#D8EDF8" has a total of 〈%response.writezs%〉, now 〈%response.write page3%〉 page per page: [〈a href= ' dispcont.asp?pag=〈%=page3%〉&pa=15 ' 〉15] bar, [〈a href=] Dispcont.asp?pag=〈%=page3%〉&pa=20 "〉20], [〈a href=" dispcont.asp?pag=〈%=page3%〉&pa=30 "〉30] strip, [〈a href=" Dispcont.asp?pag=〈%=page3%〉&pa=40 "〉40] strip [〈a href= dispcont.asp" Refresh]〈div align= "left" 〉〈table "0" cellpadding= "0" style= "font-size:9pt" 〉〈tr〉〈td〉 page number 〈/td〉〈%page2=1 for I=1 to ZS step pages if Page3=cstr (Page2) Then 〉[〈%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 = per-page Display number * page-per page display number if Sn〉zs then sn=0 rs.move ' * * * * The above paragraph is 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 page number 〈/td〉〈td〉 first access 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〉 visits to more than 100 times have 〈%=cs100%〉〈/td〉〈td〉 visits 1 are: 〈%=cs1%〉〈/td〉〈td〉 Total visits 〈%=csi%〉〈/td〉〈td〉 today's traffic: 〈%=CSDAT1 %〉〈/td〉〈/tr〉〈/table〉

Above is a complete pagination display all copy down to be available (note: Do not consider a record also does not have the situation), or that sentence only own hands to be able to have plenty of clothing, grasp the test!

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.