How to write the website statistic system with ASP

Source: Internet
Author: User
Tags date count servervariables string format table name
In the current Web site statistics System is most of the CGI, but the writing is particularly complex, and the ASP to learn simple, more and the advantages of combining the database, so the combination of their own has done the site statistics system, and we discuss the ASP to write a Web site 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 Visitor IP
Dim m_ip
M_ip=request.servervariables ("Remote_host")
Use the above statement to get the IP of the visitor.
2. Get browser information
Dim O_browser,m_browsertype
Set o_browser=server.createobject ("MSWC. BrowserType ")
M_browsertype=o_browser.browser+o_browser.version
3. Get 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

1 Get 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.

2. 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.
  
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 C Statistic Index

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)-> Feedback the registration to the user
-> users to add links to their own pages-> 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.


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.