An example of ASP statistics making

Source: Internet
Author: User

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:

The

〈% Set conn=server.createobject ("ADODB. Connection ")
connstr=" dbq= "+server.mappath (" cont.asp ") +";D efaultdir=;D river={microsoft Access DRIVER (*.mdb)}; " The
Conn.Open connstr ' * * * * is used to connect the library, cont.asp is the library file name.

Keren=request.cookies ("Keren") reads cookies,cookies named: "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 is a new visitor, add a record in the library.
RS ("cs") =1 ' write down Access count 1
rs ("IP") =request.servervariables ("remote_addr") ' Write down IP,
rs (' dat ') =now ' write down the current date time,
RS ("DAT1") =date ' writes down the current date for the first visit,
Response.Cookies ("Keren") =rs ("id") "Write a cookie with the same content as the ID."
Response.Cookies ("Keren"). expires=date+365 ' Set the valid date for cookies from now, 365 days,

else '以上是新朋友的处理办法,对老朋友怎么办呢?看下面的:
sql="SELECT * FROM tab where id="&keren '到库中去找出我们老朋友的记录
set rs=server.createobject("ADODB.Recordset")
rs.Open sql,conn, 1, 3
rs("cs")=rs("cs")+1 '好啦,找到啦,把访问次数加上1
rs("ip")=request.servervariables("remote_addr") '看看他的IP是多少了,记下来。
rs("dat")=now '记下现在的时间,也就是最后一次访问的时间,
response.cookies("keren")=rs("id") '再把cookies写进去,我不知这句是否多余,没有试。
response.cookies("keren").expires=date+365 '设置cookies过期时间,免得一年到了我就不认得他了。

end if

rs.update '该记的都记下了,更新库吧。
rs.close '关闭recordset对象。
set conn=nothing '释放conn,我还是认为connection要随开随关才对,放到SESSION中我认为最不可取。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,

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.