An example of statistical production that can number visitors and record the number of visits, IP, and time. Friends who need it can refer to it.
I made a website, and of course, like everyone else, I also put a counter on it. I kept reading the counter every day, which made me very happy. But then I thought, who on earth saw my website? Are they new friends or old friends? Nope I don’t know how many times they have come, but I still wanted to number them all, so I applied for free statistics, but I was still not satisfied after changing N numbers in a row. Alas, it seems that the only way to have enough food and clothing is to do it myself. Just do it. , I still hope that the experts will laugh at it and not ask for advice.
I took the ACCESS library as an example. In fact, to use the SQL SERVER library, you only need to change the statement of the link library.
The library structure is as follows
Library file name: CONT.ASP It was originally CONT.MDB but after it was built, the extension was changed to ASP to prevent the library from being downloaded.
Table name: tab
Field name data type description
ID Automatically number the visitor's number
IP text is used to record the visitor’s IP
dat1 date and time is used to record the last time the visitor visited
dat date and time is used to record the time of the visitor's first visit
CS number, integer used to record the number of visitor visits
The program is very simple, with only two files, dispcont.asp is used to display statistical results, and contpage.asp is used for statistical information.
Let’s first look at the statistics of CONTPAGE.ASP. The code is as follows:
- <%SetConn=Server.CreateObject(ADODB.Connection)
- Connstr=DBQ=+server.mappath(cont.asp)+;DefaultDir=;DRIVER={MicrosoftAccessDriver(*.mdb)};
- Conn.Openconnstr'***** The above statement is used to connect to the library, and cont.asp is the library file name.
- keren=request.cookies(keren)'Read cookies, the name of cookies is: keren, haha. . Ah Yu's E is a bad literary word, and he only knows how to use pinyin.
- ifkeren=then' determines whether cookes is empty. If it is empty, then it must be a new friend, otherwise it is an old friend.
- sql=SELECT*FROMtabwhereid=-1
- setrs=server.createobject(ADODB.Recordset)
- rs.Opensql,conn,1,3
- rs.addnew'If it is a new visitor, add a new record in the library.
- rs(cs)=1'record the number of visits as 1
- rs(ip)=request.servervariables(remote_addr)' note down the IP,
- rs(dat)=now'Remember the current date and time,
- rs(dat1)=date'Remember the current date and use it as the date of the first visit in the future.
- response.cookies(keren)=rs(id)'Write a cookie, the content is the same as the ID.
- response.cookies(keren).expires=date+365'Set the validity date of cookies starting from now, 365 days,
- else'The above is how to deal with new friends. What should we do with old friends? Watch below:
- sql=SELECT*FROMtabwhereid=&keren'Go to the library to find the record of our old friend
- setrs=server.createobject(ADODB.Recordset)
- rs.Opensql,conn,1,3
- rs(cs)=rs(cs)+1'Okay, found it, add 1 to the number of visits
- rs(ip)=request.servervariables(remote_addr)'See what his IP is and write it down.
- rs(dat)=now'Remember the current time, which is the time of the last visit,
- response.cookies(keren)=rs(id)' and then write cookies in. I don't know if this sentence is redundant, I haven't tried it.
- response.cookies(keren).expires=date+365'Set the cookie expiration time so that I won't recognize it after one year.
- endif
- rs.update' I have written down everything that should be written down, let’s update the library.
- rs.close'Close the recordset object.
- setconn=nothing' releases conn. I still think that the connection should be opened and closed at any time. I think it is most undesirable to put it in SESSION. 4%〉
Okay, the record is done. It has more than twenty lines of code, and it is a very simple small program.
After the program is written, how to put it on the page? It is very simple. Just find a place on the homepage and add this line of code: <img src=contpage.asp width=0 height=0>.
The next step is to show the records. There are many people who can do better than Ayu, but I still want to show off my ugliness.
File name: dispcont.asp, please see the code:
- <%
- SetConn=Server.CreateObject(ADODB.Connection)
- Connstr=DBQ=+server.mappath(cont.asp)+;DefaultDir=;DRIVER={MicrosoftAccessDriver(*.mdb)};
- Conn.Openconnstr'***** The above statement is used to connect to the library, and cont.asp is the library file name.
- page3=request(pag)
- ifpage3=thenpage3=session(contpag)'Number of pages, current page
- ifpage3=thenpage3=1
- pa=request(pa)
- ifpa=thenpa=session(contpa)'Number of displays per page
- ifpa=thenpa=15' displays 15 items per page by default, which can be changed arbitrarily
- session(contpag)=page3
- session(contpa)=pa
- pages=pa'Display number per page******************The above program is used to implement the paging function
- SQL=SELECT*FROMtaborderby-dat,-id
- dimrs
- Setrs=Server.CreateObject(ADODB.RecordSet)
- rs.Opensql,conn,1,1
- csi=0
- cs1=0
- cs100=0
- csdat1=0
- dowhilenotrs.eof
- csi=csi+rs(cs)
- ifrs(cs)=1thencs1=cs1+1
- ifrs(cs)〉=100thencs100+1
- ifdatevalue(rs(dat))=datethen
- csdat1=csdat1+1
- endif
- rs.movenext
- loop
- ZS=RS.RECORDCOUNT
- '************************************************ ****8The following program is used for paging display
- %〉
- 〈head〉
- 〈title〉Excellent Computer Statistics〈/title〉
- 〈/head〉
- 〈bodystyle=font-size:9ptbgcolor=#D8EDF8〉
- There are 〈%Response.Writezs%〉 records in total. The current page is 〈%Response.Writepage3%〉. Each page displays: [〈ahref=dispcont.asp?pag=〈%=page3%〉&pa=15〉15], [<ahref=dispcont. asp?pag=〈%=page3%〉&pa=20〉20] items, [〈ahref=dispcont.asp?pag=〈%=page3%〉&pa=30〉30] items, [〈ahref=dispcont.asp? pag=〈%=page3%〉&pa=40〉40]
- [〈ahref=dispcont.asp〉Refresh]
- 〈divalign=left〉
- 〈tableborder=0cellpadding=0style=font-size:9pt〉
- 〈tr〉〈td〉Page number〈/td〉〈%page2=1
- fori=1tozssteppages
- ifpage3=cstr(page2)then
- %〉〈td〉[〈%Response.Writepage2%〉]〈/td〉
- 〈%else%〉
- 〈td〉〈ahref=dispcont.asp?pag=〈%Response.Writepage2%〉〉[〈%Response.Writepage2%〉]〈/td〉
- <%endif
- page2=page2+1
- next
- sn=pages*(page3-1)'Current record number=number displayed per page*number of pages-number displayed per page
- ifsn〉zsthensn=0
- rs.movesn,1
- '************************************The above paragraph is used for paging
- %〉〈/tr〉〈/table〉
- 〈/div〉〈tablestyle=font-size:9ptwidth=100%bordercolorlight=#000000border=1bordercolordark=#FFFFFFbgcolor=#A4D1E8cellspacing=0cellpadding=3〉
- 〈tr〉〈td〉Number〈/td〉〈td〉Last visited homepage〈/td〉〈td〉Last visited IP〈/td〉〈td〉Number of homepages〈/td〉〈td〉First visit date〈/td〉 〈/tr〉〈%
- fori=1topages
- 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
- ifrs.eofthenexitfor
- next
- rs.close
- %〉
- 〈tr〉〈td〉Total〈%=zs%〉〈/td〉〈td〉There are those who have visited more than 100 times〈%=cs100%〉〈/td〉〈td〉There are those who have visited 1 : 〈%=cs1%〉〈/td〉〈td〉Total number of visits 〈%=csi%〉〈/td〉〈td〉Today’s visits: 〈%=csdat1%〉〈/td〉〈/tr〉
- 〈/table〉
The above is a complete paging display that can be copied and used (note: the situation where there is no record is not considered). As the saying goes, only by doing it yourself can you have enough food and clothing, so hurry up and try it out!