Most of the current website statistics systems are CGI, but the compilation is particularly complicated. asp is simple to learn and has the advantages of combining with databases, so I will discuss with you how to compile a Website Statistics System Based on my previous website statistics system.
Everyone has seen Netease's website statistics system, which can count the total traffic, average daily traffic, daily traffic, maximum traffic, maximum access date, daily traffic analysis, and monthly traffic analysis, weekly Traffic Analysis, browser analysis, and so on.
In fact, the key to making an asp Access statistics system is the design of the system table structure. And how to collect user CGI variables and display user information. That is to say, the key to the system is two ASP programs, statistical programs and display programs.
First, let's take a look at how to collect user access information.
When writing access statistics, we need to know the following information about the user. The visitor's IP address (the visitor's IP address list can be formed based on the access IP address ), visitor's browser and Operating System (view the ratio of visitor's browser to the operating system and all visitor's browsers to the operating system), visitor's access time (perform daily access volume analysis, Monthly Access volume analysis, weekly Traffic Analysis). Let's take a look at the statements that use ASP to obtain the above information:
1. Obtain visitor IP
Dim M_IP
M_IP=Request.Servervariables("REMOTE_HOST")
The preceding statement can be used to obtain the visitor's IP address.
2. Obtain browser Information
Dim O_Browser,M_BrowserType
Set O_Browser=Server.Createobject("MSWC.BrowserType")
M_BrowserType=O_Browser.Browser+O_Browser.Version
3. Obtain 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. Obtain the user's operating system.
Use the following statement in ASP to obtain the visitor's http_user_agent string.
Dim StrUserAgent
StrUserAgent=Request.ServerVariables("HTTP_USER_AGENT")
This string is generally in the following format:
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
The above string indicates that the visitor uses Windows 98 and the browser uses MSIE 4.01. However, the string format is not fixed and can be changed by yourself.
The other main useragent strings we see are as follows:
Use the IE 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)
Use the Netscape 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)
Use the Opera Browser:
Mozilla/4.0 (compatible; Opera/3.0; Windows 95) 3.50b10
FrontPage Editor:
Mozilla/2.0 (compatible; MS FrontPage 3.0)
Use the sun operating system:
Mozilla/3.01Gold (X11; I; SunOS 5.7 i86pc)
Use a PowerPC Mac:
Mozilla/4.0 (compatible; MSIE 4.5; Mac_PowerPC)
By analyzing the above strings, we can find out the rule and write a sub-program to determine the visitor's operating system. In addition, Browser needs to be updated to determine browser-type controls in ASP. INI file, so we can use this string to determine the browser attributes.
2. How can we count websites?
We can add the following statement to the user's home page:
<A href = "http://www.abc.com/viewer.asp? Userid = username "> </a> which user is the specific userid? Note that users and visitors are not a concept.
With the above strings, we can collect user access data and provide users with links to viewing data. When we look at the page with Netease's statistical system, we will find that it will return an icon to the user, and we can implement this function in counter. asp.
Add: Response. Redirect "http://www.abc.com/abc.gif"
This statement can be returned to the user after statistics are collected.
Designing a table structure is an extremely important task. Its rationality is closely related to programming.
A website statistics system should have a user table and a statistical value table.
This user table is the table that retains the registered user information. The statistical value table is the table that records each statistical indicator value of the user. In the statistical value table, we can specify the user's statistical indicators. We can use an id value to represent each indicator. Here we will give 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 Statistical Indicator ID
Value C statistical indicator value
ID list:
Table Name: id_table
Field Type
Id c Statistical Indicator ID
Idvalue C statistical indicator description
With these three tables, we can start.
For example, you can specify the following ID
Id idvalue
101 total visits
201 visits per day
202 2-day access volume
::
::
231 access volume on the 31st day
To start statistics on users, we must first register users. The procedure for using users is as follows:
Enter the Registry-> the initial user's value table (add the corresponding ID)-> feedback the registration information to the user
-> Add a link to your page.-> Start statistics.
We can collect all the data, so we began to compile the ASP statistics page.
This page is called count page, counter. asp
This ASP code requires it to collect data, save data, and update data as follows:
Collect the user name, determine whether the user name is legal, collect the visitor's information, process the information, save and update the database, and return the logo icon.
Use counter. asp to call asp? User = ABC.
To collect user names, we can use the corresponding method of the request object, then check the user table to determine whether the user is legal, and then obtain the information, and use the method we mentioned above to obtain the information, the data is then processed and stored in the data table, but the most important thing is how to update the data, such as the hourly access statistics and hourly statistics of the day, how we update the data every day is the main point of this program. We can use several methods, such as updating the records every hour every day. We adopt updating at midnight every day, we update the data of each day of each month on the day of the month switch.