How to write a website statistics system with ASP

zhaozj2021-02-11  253

How to write a website statistics system with ASP

Most of the current website statistics system is CGI, but it is particularly complex, and ASP has simple, more and more and database-combined advantages, so combined with their own website statistics system, and to explore the ASP. Write a website statistics system.

Everyone has seen Netease website statistics system, which can count the total number of visits, daily average access, maximum visits, maximum visits, maximum access date, daily flow analysis, monthly flow analysis, survival analysis, browser analysis ,and many more.

In fact, the key to the access statistics system of an ASP is the design of the system surface structure. And how to collect users 'CGI variables, how to display users' information. That is to say, the key to the system is two ASP programs, statistical procedures, and display programs.

First let's take a look at how to collect users' access information.

We write access statistics to know the following information, visitors 'IP (can form a visitor IP list according to access IP), visitors' browser and operating system (statistical visitor browser and operating system and all visitor browsing Scale and operating system scales), visitors' access time (performed day visits, monthly visual analysis, weekly visual analysis), let's take a look at the statement of the above information with ASP:

1. Get visitors IP

DIM M_IP

M_ip = request.serverVariables ("remote_host")

Use the above statement to get the visitor's IP.

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)

4, acquire the user's operating system.

The following statement can be used in ASP to get the visitor's http_user_agent string.

Dim StrUserage

STRUSERAGENT = Request.ServerVariables ("http_user_agent")

This string is generally as follows:

Mozilla / 4.0 (Compatible; Msie 4.01; Windows 98)

The above string can indicate that the operating system used by the visitor is Windows 98, the browser is MSIE 4.01, but this string format is not fixed, and can be changed by himself.

It usually we see some of the other main useERAGENT strings are as follows:

Use IE browsers:

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 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)

Use Opera's 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 PowerPC's MAC:

Mozilla / 4.0 (compatible; msie 4.5; mac_powerpc)

By analyzing the above strings, we can find the law, write a subroutine to determine what operating system used by the visitor, but also updates the browser.ini file due to the judgment of the browser type in ASP, so we can Combine this string to determine the browser properties.

What kind of way we have a statistics website?

We can let users join the following statement on his homepage:

The above Userid is a specific user, pay attention to the user and visitors are not a concept.

With the string above us, we can collect the user's access data and provide users with links to view data. When we look at the page of Netease's statistical system, it will find that it will return to the user an icon, we can implement this function in Counter.asp.

Join: response.redirect "http://www.abc.com/abc.gif"

This statement we can add to the user after statistical data acquisition.

How to design a data table structure?

The design table structure is an extremely important job, and its reasonable is closely related to the program's preparation.

A website statistics system should have a user table, a statistical value table.

This user table is also a table that retains registered user information, and the statistical table is a table that records each statistical indicator value of the user. In the table of statistics, we can specify the user's statistical indicator, we can use each indicator with a ID value, here we are simple.

user table:

Table name: regist_table

FIELD TYPE

Username C User Name

Password C password

Regdate C Registration time

Table:

TABLE NAME: Value_Table

FIELD TYPE

Username C User Name

ID C statistical indicator ID

Value I

DateTime C statistical indicator value

ID list:

Table name: ID_TABLE

FIELD TYPE

ID C statistical indicator ID

IdValue C Description of Statistical Index

With these three tables, we can start doing.

If we can specify the following ID

ID IdValue

101 total visual volume

201 1 visit

202 2nd visits

::

::

231 31 visit

To start statistics to users, we must first let users register, the procedures used by users are as follows:

Fill in the registry -> The value of the initial user (join the corresponding ID) -> feedback the registration information to the user

-> Users to join the link on their own page -> Start Statistics

We can collect data we can pick it, then we start to prepare the statistics page of the ASP.

This page we call count page, counter.asp

This ASP code we need to collect data and save data and update data as follows:

Collect user names, determine if the username is legal, collecting the information, processing information, saving and updating the database, returning the logo icon.

Call this ASP in the way with counter.asp? User = abc.

Collecting Username We can get the corresponding method of the Request object, then check the user table to determine if the user is legal, then take information, take information with the method of obtaining the corresponding information told above, and then saved in the data table, but The most important thing is how to update the data, such as access statistics per hour on the same day, how do we update the daily data is this program, we can take several ways, such as every day Updates for each hour of records We take 12 o'clock every night, and we will update the day of every day of the month.

Let me talk about the specific process, and for the month statistics:

1, get the date of the last statistics

2, get the current date time, the current month and transform into the corresponding ID

3. Judging whether the current month is the same as the last month, if the same is added to the total number, the current month ID is accumulated 1, if different, clear all month IDs, only give the total ID plus 1

4. According to month statistics, we can do a small time statistics, weekly statistics, day statistics.

As mentioned above, we can do a statistical page. Pay attention to the assignment of each ID to be clarified.


New Post(0)