About Page Counter
PageCounter is an 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.
Methods include:
- 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.
Syntax for each method
- MyPageCounter.Hits( [pathInfo] )
- MyPageCounter.PageHit()
- MyPageCounter.Reset( [pathInfo] )
Note: pageInfo is an optional parameter that specifies the PATH_INFO of the Web page using the format /virtualdirectoryname/filename.asp. If this parameter is not specified, the hit count for the current page is displayed.
Simple Example
The following example uses the PageCounter object to track the number of visitors to the page and sends a special message to the tenth visitor.
--- PageCount.asp --- <% Set MyPageCounter = Server.CreateObject("MSWC.PageCounter") MyPageCounter.PageHit If MyPageCounter.Hits = 10 Then %> You are the lucky 10th Customer!!! <BR> <% Else %> Sorry, you are customer #<%= MyPageCounter.Hits %> <BR> <% End If %>