Recommended: Dynamic web enthusiasts: Asp function filtering HTML Asp filtering Html code is the following referenced content: Function RemoveHTML(strHTML) Dim objRegExp, Match, Matches Set objRegExp = New Regexp obj
An example of statistical production that can number visitors, record number of visits, IP, and time
I take the ACCESS library as an example. In fact, if you use the SQL SERVER library, just change the statements of the link library. The library structure is as follows
Library file name: CONT.ASP was originally CONT.MDB, but after the build, 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 time is used to record the last visitor visitor
dat date time is used to record the time when the visitor first visits
CS number, integer type is used to record visits by visitors
The program is very simple, with only two files. Dispcont.asp is used to display statistical results, and contpage.asp is used to display statistical information.
Let’s first look at the statistics of CONTPAGE.ASP, the code is as follows:
| The following is the quoted content: <% Set Conn=Server.CreateObject(ADODB.Connection) Connstr=DBQ= server.mappath(cont.asp) ;DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}; Conn.Open connstr ' '***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. . The stinky thing about Ayu's E literature is that he only knows how to use pinyin. if keren= then ' 'Judge whether cookies are empty. If they are empty, they must be new friends, otherwise they are old friends. sql=SELECT * FROM tab where id=-1 set rs=server.createobject(ADODB.Recordset) rs.Open sql,conn, 1, 3 rs.addnew ' 'If it is a new visitor, add a new record in the library. rs(cs)=1 ' ' Note the number of visits is 1 rs(ip)=request.servervariables(remote_addr) ' 'Tell me the IP, rs(dat)=now ' 'Tell the current date and time, rs(dat1)=date ' 'Tell the current date, and the date to be used for the first visit in the future. response.cookies(keren)=rs(id) ' 'Write a cookie and the content is the same as the ID. response.cookies(keren).expires=date 365 ' 'Set the valid date of cookies from now on, 365 days, else ' 'The above is the way to deal with new friends. What should I do with old friends? Look at the following: sql=SELECT * FROM tab where id=&keren ' ' Go to the library to find the records of our old friends set rs=server.createobject(ADODB.Recordset) rs.Open sql,conn, 1, 3 rs(cs)=rs(cs) 1 ' 'Okay, found, add 1 visits rs(ip)=request.servervariables(remote_addr) ' 'See what his IP is and write it down. rs(dat)=now ' 'Tell me the current time, that is, the time of the last visit, response.cookies(keren)=rs(id) ' ' Then write cookies in. I don't know if this sentence is redundant, so I didn't try it. response.cookies(keren).expires=date 365 ' 'Set the expire time of cookies so that I won't recognize him if one year comes. end if rs.update ' 'I have recorded everything I should remember, update the library. rs.close ' 'Close the recordset object. set conn=nothing ' 'Release conn, I still think the connection should be turned on and off as soon as possible. I think it is the most undesirable to put it in SESSION. 4 %> |
Okay, the record is done, there are more than twenty lines of code, a very simple small program. After the program is written, how can it be placed on the page? It's 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 display the record.
File name: dispcont.asp, please see the code:
| The following is the quoted content: <% Set Conn=Server.CreateObject(ADODB.Connection) Connstr=DBQ= server.mappath(cont.asp) ;DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}; Conn.Open connstr ' '***The above statement is used to connect to the library, and cont.asp is the library file name. page3=request(pag) if page3= then page3=session(contpag) ' 'Number of pages, current page if page3= then page3=1 pa=request(pa) if pa= then pa=session(contpa) ' 'Number of display per page if pa= then pa=15 ' 'By default, 15 items are displayed per page, and can be changed at will session(contpag)=page3 session(contpa)=pa pages=pa ' 'Number of display per page******************* The above program is used to implement the pagination function 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 while 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 program is used for pagination display %> <head> <title>Online Statistics</title> </head> <body style=font-size: 9pt bgcolor=#D8EDF8> There are a total of <%Response.Write zs%> records, and now the <%Response.Write page3%> page displays each page: [<a href=dispcont.asp?pag=<%=page3%>&pa=15>15], [<a href=dispcont.asp?pag=<%=page3%>&pa=20>20], [<a href=dispcont.asp?pag=<%=page3%>&pa=30>30], [<a href=dispcont.asp?pag=<%=page3%>&pa=40>40] [<a href=dispcont.asp>Refresh] <div align=left> <table border=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 %><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 display per page * number of pages - number of display per page if sn>zs then sn=0 rs.move sn,1 ' '************************************ The above paragraph is used for paging %> </tr></table> </div> <table style=font-size: 9pt width=100% bordercolorlight=#000000 border=1 bordercolordark=#FFFFF bgcolor=#A4D1E8 cellpacing=0 cellpadding=3> <tr><td>Number</td><td>Last visit to home page</td><td>Last visit to IP</td><td>Number of home page</td><td>Number of 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>The number of visits is more than 100 times<%=cs100%> </td><td>The number of visits is 1: <%=cs1%></td><td>Total number of visits is <%=csi%></td><td>Today's visits: <%=csdat1%></td></tr> </table> |
' '****************************** The above is the complete page display. All of them are available. No record nor any situation is considered.
Share: Tetris game written in ASP The following is the referenced content: <%If Not Request.QueryString(Ven) = T then%> <HTML> <HEAD> <META NAME