Research on ASP Programming website Traffic Statistic system

Source: Internet
Author: User
Tags date format count key return servervariables string format table name
Traffic | statistics

ASP learn simple, more and the advantages of the combination of the database, so combined with their own once done the site statistics system, and you discuss ASP to write the website statistics system.

We have seen NetEase's website statistics system, it can statistics total traffic, the average daily traffic, the day visits, the highest traffic, the highest access date, daily traffic analysis, monthly traffic analysis, weekly flow analysis, browser analysis, and so on.

In fact, to do an ASP access statistics system is the key to the system table structure design. And how to capture the user's CGI variables, and how to display the user's information. In other words, the key of the system is two ASP programs, statistical programs and display programs.

First we look at how to capture the user's access information.

We write access statistics need to know the users of the following information, the visitor's IP (according to the Access IP can form a visitor IP list), the visitor's browser and operating system (statistics visitor's browser and operating system and all visitors browser and operating system scale map), visitor's visit time (Carry on daily traffic analysis, Monthly traffic analysis, weekly traffic analysis), below we look at the use of ASP to obtain the above information statements:

1, get the visitor IP

Dim m_ip

M_ip=request.servervariables ("Remote_host")

Use the above statement to get the IP of the visitor.

2, access to browser information

Dim O_browser,m_browsertype

Set o_browser=server.createobject ("MSWC. BrowserType ")

M_browsertype=o_browser.browser+o_browser.version

3. Access time

Dim M_datetime

M_datetime=year (Date ()) & "/" &right ("0" &month (date ()), 2) & "/" Right ("0" &day (date ()), 2) & "/" &right ("0" &hour (Time ()), 2) & ":" &right ("0" &minute (Time ()), 2) & ":" &right ("0" & Second (Time ()), 2

4, access to the user's operating system.

Use the following statement in the ASP to get the Http_user_agent string for the visitor.

Dim struseragent

Struseragent=request.servervariables ("Http_user_agent")

This string is typically in the following format:

mozilla/4.0 (compatible; MSIE 4.01; Windows 98)

The string above can indicate that the visitor is using an operating system that is Windows98 and the browser is MSIE 4.01, but the string format is not fixed and can be changed on its own.

Some of the other major useragent strings we've seen are as follows:

Use IE's browser:

mozilla/2.0 (compatible; MSIE 3.01; Windows 95)

mozilla/4.0 (compatible; MSIE 4.0; Windows 95);

mozilla/4.0 (compatible; MSIE 4.01; Windows 98)

mozilla/4.0 (compatible; MSIE 5.0; Windows 98);

mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)

Using Netscape's browser:

Mozilla/4.03(en) (WIN95; I)

Mozilla/4.08(en) (WinNT; U NAV)

Mozilla/4.5(en) (WinNT; U

Mozilla/3.04gold (WIN95; I)

Using Opera's browser:

mozilla/4.0 (compatible; opera/3.0; Windows 3.50B10)

FrontPage Editor:

mozilla/2.0 (compatible; MS FrontPage 3.0)

Using the Sun operating system:

Mozilla/3.01gold (X11; I; SunOS 5.7 i86pc)

Mac machine with PowerPC:

mozilla/4.0 (compatible; MSIE 4.5; MAC_POWERPC)

By analyzing the strings above, we can find the rules, write a subroutine to determine what kind of operating system the visitor is using, and because the browser-type control in the ASP needs to update the Browser.ini file, we can combine this string to determine the browser properties.

What kind of way do we use to count websites?

We can have the user add the following statement to his home page:

<a Href= "Http://www.abc.com/viewer.asp?userid=username" > </a> The above userid is specific to which user, be aware that users and visitors are not a concept."

Through the string above we can collect the user's access data, and provide users with a link to view the data. When we see the page with NetEase's statistical system, we will find that it will return to the user an icon, we can implement this function in the counter.asp.

Add: Response.Redirect "Abc.gif"

This statement can be added to the user after the collection of statistical data.

How do I design a data table structure?

The design of the table structure is an extremely important work, and its reasonableness is closely related to the programming.

A website statistic system should have a user table, a table of statistics.

This user table is the table that keeps the registered user information, and the statistic table is the table that records the user's each statistic index value. In the table of statistics we can specify the user's statistics, we can use an ID value to represent each indicator, here we have a simple example.

User table:

Table name:regist_table

Field type

Username C User Name

Password C password

RegDate C Registration Time

Value table:

Table name:value_table

Field type

Username C User Name

ID c Statistic Indicator ID

Value I

Value of datetime C statistic metric

ID List:

Table name:id_table

Field type

ID C statistic Indicator ID

Description of Idvalue C statistical indicators

 

With these three tables, we can begin to do it.

If we can specify the following ID

ID idvalue

101 Total Traffic

201 1st Visit Volume

202 2nd Visit Volume

:    :

:    :

231 31st Visit Volume

To start the statistics for the user we have to register the user first, the user's use of the process is as follows:

Fill in the registry-> The initial user's value table (add the corresponding ID)-> The registration feedback to the user-> users to add a link on their own page-> start statistics

Can collect the data we all can gather, then we begin to compile the ASP the statistic page.

This page we call the Count page, counter.asp

This ASP code we need to get it to collect data and save data and update data according to the following process:

Collect the username, judge whether the user name is legitimate, collect the visitor's information, process the information, save and update the database, and return the logo icon.

Call this ASP using COUNTER.ASP?USER=ABC this way.

Acquisition of user name we can use the corresponding method of the request object to obtain, and then check the user table to determine whether the user is legitimate, and then take the information, we mentioned above to obtain the appropriate information methods to obtain information, and then processed in the data table, but the most important is how to update the data, How do we update our daily data, such as hourly statistics, hourly statistics, and so on, we can take several ways, such as updating our records every hour of the day and we take them 12 o'clock every day at midnight, For each of the monthly data we update on the day of the month switch.

Let me talk about the specific process, by month statistics Example:

1, to arrive at the date and time of the last statistic

2, the current date and time, the current month and converted to the corresponding ID

3, to determine whether the current month is the same as the previous month, if the same, add 1 to the total, the current month's ID cumulative 1, if not the same, clear 0 of all the month ID, only to the total ID plus 1

4, according to the monthly statistics we can do the hour statistics, weekly statistics, day statistics.

We can do the statistics page according to the process as above, pay attention to the distribution of each ID to classify clearly the meaning of the representative should be clear.



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.