What is PageCounter and how do I use it?

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:

  1. Hits - Displays the number of times that a specified URL has been opened.
  2. PageHit - Increments the Hit Count.
  3. Reset - Sets the hit count for a specified page to 0.

Syntax for each method

  1. MyPageCounter.Hits( [pathInfo] )
  2. MyPageCounter.PageHit()
  3. 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 %>
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

Where can I find documentation for ServerObject's AspMail component?

This documentation can be found at: http://www.serverobjects.com/products.html For...

How do I upload files through my web pages?

You can use Software Artisan's SAFileUP. This is an ASP component that allows you to upload files...

How do I setup Microsoft Outlook Express to read my e-mail?

Follow these steps: Open Microsoft Outlook Express. From the Tools menu, click...

How do I setup Netscape Messenger to read my e-mail?

Follow these steps: Open Netscape Navigator. Click the Edit menu and then click Preferences......

How do I setup Eudora to read my e-mail?

Follow these steps: Open Eudora. Click the Tools menu and then click Options...  ...