Access
Three ways to get the number of visits to the homepage by ASP technology
Department of Automation Engineering, Huazhong University of Technology Zhou Xi Hau and
ASP is the abbreviation for Microsoft Active Server Pages, the Dynamic Servers home page.
It is a server-side scripting environment that interprets scripts on a Web server and can combine HTML pages, script commands, and ActiveX components to create dynamic, interactive, efficient
Web pages and powerful Web-enabled server applications. ASP can publish a variety of Dynamic data on any Microsoft Web server, and ASP applications are easy to develop and modify.
The reason why ASP technology is easy is that ASP technology makes full use of powerful embedded objects and ActiveX components to perform tasks. An ActiveX component is code that is contained in a dynamic-link library (. dll) or executable (. exe) executable or set of tasks. Because components can perform common tasks, you do not have to create the code to perform these tasks yourself, and you can use components directly as scripts and as basic building blocks for web-based applications. As long as you know how to access and control the objects that the component provides, even the novice who writes the script can write the script without knowing how the component works.
To use the object provided by the component, first create an instance of the object and assign the new instance to the variable name. Use the ASP's Server.CreateObject method to create an instance of an object. The object instance is then named with the variable assignment instruction in the scripting language. When you create an object instance, you must provide the registration name (PROGID) for the instance.
For a Web site, we usually need to record the number of times it was accessed. In this paper, three kinds of methods are put forward for reference.
< a > Using the page Counter component
The page Counter component can create PageCounter objects to record and display the number of times a Web page is opened. At a certain time, this object writes the number of accesses to a text file so that the data is not lost when the server shuts down. The page Counter component uses an internal central Management object to record the number of times each page in the application is opened. When you use the Server.CreateObject method to create an instance of a PageCounter object on a page, the object obtains the current number of accesses to the specified Web page from the central Management object, and you can use the method that the object already has.
Syntax: <% Set oVar = Server.CreateObject ("MSWC. PageCounter ")%>
Parameters: OVar Specifies the PageCounter object created by calling Server.CreateObject
's name.
Method
Hits displays the number of times the specified URL was opened.
PageHit increase the number of visits.
Reset sets the number of accesses to the specified page to 0.
Note: The PageCounter object is not an inline object and must be registered. When this object is compiled or registered, the page counter adds MSWC to the registry. PageCounter key. The key is added under HKEY_CLASSES_ROOT and includes the following named values.
2. File_Location String,
The pathname and file name of the file that specifies the number of accesses to the record. The default file name is hitcnt.cnt. This file is stored in the Windows directory.
2. Save_count DWORD Type,
Indicates the number of accesses before the number of accesses is stored to the Hit Count Data file. Note that this is the total number of accesses rather than the number of accesses per page. The default value is 25.
The following example uses the PageCounter object to track the number of visitors and send a specific message.
<% Set mypagecounter = Server.CreateObject ("MSWC. PageCounter ")
Hitme = Mypagecounter.hits
%>
You are the first <%= hitme%> visitor.
< two > Using the File Access component
Because the Page Counter component is not installed with IIS, it must be installed before it can be used. If you do not have the Page Counter component installed, you can take the file Access component. The files access component can be used to access methods and properties of the computer's file system. Users can use the file access component to create a FileSystemObject object that provides methods, properties, and collections to access the file system.
The following example shows how many times the access is logged.
<% ' (1)
Do While application ("bar") = 1
Application.Lock
Application ("bar") = 0
Application.UnLock
%>
<% ' (2)
Set fs = CreateObject ("Scripting.FileSystemObject")
Set FR = fs. OpenTextFile ("Visitors.txt", Forreading,tristatefalse)
' Indicates that file Visitors.txt is opened in read-only mode, ASCII format, and returns a
The ' TextStream object fr,visitors.txt the number of times it was accessed.
Visitors = fr. Read (10)
Fr. Close
Count = CLng (visitors)
Count = Count + 1 adds 1 to the number of accesses.
Visitors = CSTR (count)
Set FW = fs. OpenTextFile ("Visitors.txt", 2,tristatefalse)
Fw. Write (visitors) ' writes a new number of accesses Visitors.txt save
Fw. Close
%>
<% Application.Lock &nbs