The Page Counter component creates a PageCounter object that counts and displays the number of times a Web page has been opened. At regular intervals the object writes the number of hits to a text file so that in the event of a server shutdown, the data is not lost. The Page Counter component uses an internal Central Management object to record how many times each page in the application has been opened.
When an instance of the PageCounter object is created on a page by using the Server.CreateObject method, the object retrieves the current hit count for the specified Web page from the Central Management object. The object can then be manipulated with the methods it exposes.
The Page Counter component uses the following files:
File Names | Description |
Pagecnt.dll | The Page Counter component. |
Hit Count Data file | The text file to which the Page Counter component saves the current hit count. |
Set oVar = Server.CreateObject( "MSWC.PageCounter" )
The Page Counter adds the key MSWC.PageCounter to the registry when the object is compiled or registered. The key is added under HKEY_CLASSES_ROOT and contains the following named values.
Named Value | Description |
File_Location | A string that specifies the path and filename of the Hit Count Data file. The default filename is Hitcnt.cnt. This file is located in your Windows directory. |
Save_Count | A DWORD that specifies the number of hits before the hit count is saved to the Hit Count Data file. Note that this is the total number of hits, not the number of hits per page. The default value is 25. |
Hits | Displays the number of times that a specified URL has been opened. |
PageHit | Increments the Hit Count. |
Reset | Sets the hit count for a specified page to 0. |
The following example uses the PageCounter object to track the number of visitors to the page and sends a special message to the one millionth visitor.
<%
Set MyPageCounter = Server.CreateObject("MSWC.PageCounter")
HitMe = MyPageCounter.Hits
If HitMe = 1000000 Then
%>
You are the lucky 1,000,000th Customer!!! <BR>
<% Else %>
Sorry, you are customer #<%= HitMe %> <BR>
<% End If %>