The page Counter (page Counter) component is used to count the number of times each page is accessed, which periodically stores the statistics in a text file on the server disk---------the number of access statistics files, so the current data is not lost when there is an outage or error message.
1, create the page Counter component instance Object
The page counter component is included in the Pagecnt.dll file. When you use the Server.creatobject method to create an instance of a page Counter Component object on a page, the object obtains its current number of accesses from the central management object for the specified Web page, and then it can be manipulated using methods that are already in use by the object. The syntax format is as follows:
Set 实例对象名=Server.CreateObject("MSWC.PageCounter")
2, the Page Counter object method
The Page Counter object provides a way to increase the number of visits to the access count data file and to read and reset the sum of access counts. The description of each method is shown in the following table:
Method |
Description |
Syntax format |
Hits |
Returns the number of accesses to the Web page specified by Page_path, and returns the number of accesses to the current page if Page_path is omitted. |
Object.hits ([Page_path]) |
Pagehite |
Increases the number of times the current page is accessed. |
Object.pagehit |
Reset |
Sets the number of accesses to the Web page specified by Page_path to 0, and if Page_path is omitted, the current page is set to 0. |
Reset ([Page_path]) |
3, Example 1: Use the page Counter component to create a Web page counter.
-------------------pagecounter.asp code is as follows----------------------
<%
Set mypagecounter=server.createobject ("MSWC. PageCounter ")" Creates an PageCounter object instance.
Mypagecounter.pagehit ' increases the counter value for this page. The
If Request ("reset") = "on" then "commits the reset information."
Mypagecounter.reset () Resets the counters for this page.
End If
%>
<body
<p><center><b>
<font face= "Chinese Cloud" size= "color=" "#cc9999" > This Web page has been browsed <%= Mypagecounter.hits%> times. </font>
</b></center></p>
<center><form name= "PageCounter" method= "get" action= "pagecounter.asp"
<input type= "Submit" value= "click Page"
<input type= "checkbox" name= "Reset" > Reset Web page counters
</center>
</form>
</body>
The Counter component (counters) is used to create an counters object instance. Create only one counters object on a Web site, through which you can create any number of independent counters. A counter is a constant value that contains integers, and you can use the method of the counter component to control the counter.
1, create the Counter component instance object
The counter component is contained in the Counters.dll file, and all counters created through the component are stored in a text file named Counters.txt. If you add the following to the application's Global.asa file, you can create an instance of the counters object at once on the Web server.
<OBJECT RUNAT="Server" SCOPE="Application" ID="Counter" PROGID="MSWC.Counters"></OBJECT>
Once you create a counter object, it continues until it is deleted, and you can control the counter using the object's methods throughout the application scope. For example, if you display and add a value for a counter called Hitcount on a page named Page1.asp, and then add a Hitcount value on a page called Page2.asp, the two pages will increase the value of the same counter. If the value of the counter is increased to 34 when the page1.asp is accessed, the access page2.asp will increase the hitcount to 35, and the next visit to Page1.asp, Hitcount will increase to 36.
2, the method of counters object
After you create a counter object, you can use the method of the object to return the value of the counter, add a counter value of 1, remove the counter from the Counters.txt file, and set the counter's value to a specific integer. The description of each method is shown in the following table:
Method |
Description |
Syntax format |
Get |
The method returns its current value based on the name of the counter, and if this counter does not exist, the method creates it and adds 0 to it. |
Counters.Get (CounterName) |
Increment |
The method adds the value of the counter by 1 and returns a new value for the counter, based on the name of the counter. If the counter does not exist, this method creates it and sets its value to 1. |
Counters.Increment (CounterName) |
Remove |
This method deletes counters from counter objects and Counters.txt files based on the name of the counter. |
Counters.remove (CounterName) |
Set |
This method sets the counter to a specified integer value, based on the name of the counter, and returns the new value. If the counter does not exist, this method creates the counter and sets its value to this integer. |
Counters.Set (Countername,int) |
Note: Parameter countername is a string that specifies the name of the counter. The parameter int specifies a new integer value for this counter.