More advanced HTML features: Access Counter

We have created a way for users at Lehigh to count the number of times any selected page has been accessed. The code for our counter was obtained from Stefan Powell, although a few changes were made to make the program work on Lehigh's WWW Server..


Instructions for Using the Access Counter

Introduction: What is it and why would I want to use it?

The access counter is like an odometer, except instead of counting the number of miles you have travelled it counts the number of times your web page is read.

 It looks exactly like this --> 

 However, it usually shows up in a sentence that says something similar to:

 The page has been read  times.

 or

 Including you,  people have visited this page

 You should only be interested in using this counter if you want to include sentences such as those just displayed in any of your documents. If this all seems like too much work, or you don't care to let the people reading your page how many times the page has been accessed, then you needn't read any further. However, if you think this is a good, attractive, informative, feature, please read on for instructions on how to implement it.

Placing a Counter Image in Your Document

The counter is placed in your document with an <IMG SRC=""> tag. Specifically, the tag should look almost like:
 <IMG SRC="http://www.lehigh.edu/cgi-bin/counter.xbm?unique_name">
where unique_name is any name (with no spaces or special characters other than an underscore) that you choose, but choose one that will be unique. As a convention, let us suggest that you start the name with your username and an underscore. So, for instance, if your username is abc0, then you would choose abc0_homepage as the name for your home page counter.

 The counter is initiated with a count of zero. Don't let this convince you it isn't working. To check it, you need to reload the document. If you simply use the Back and Forward keys to re-visit your page, it will not increment the counter.

 You may also initiate the counter with a number other than zero. To do this, you would add a parameter to the counter with the initial count. An example is,

 <IMG SRC="http://www.lehigh.edu/cgi-bin/counter.xbm?abc0&COUNT=57">
This example creates a counter called abc0 with an initial count of 57. Note: The word COUNT must be in upper case letters. After being initialized, the counter program ignores the COUNT parameter.
 
 

How does it work (for those who are interested)

It may seem strange to you that the counter is implemented with the <IMG SRC=""> tag, as it did to us when we first encountered it. But, in order to dynamically update the counter, a program must be run each time the page containing the counter is requested. There are several ways for this to happen: The first two items in the list are a lot more obvious than the last one. If you take a look at any one of our lists of home pages produced by people at Lehigh, you will see an example of the first option. The number of items on the list is updated everytime the document is requested. We don't have examples of the second option because it isn't available on Lehigh's server.

 When a document is requested, the server sends the document to the client (browser). If the document includes in-line images, then those are also sent to the client. In the case of the counter, the image file does not exist, but is dynamically created based on the value stored in a file. First the file is read, the number is incremented by one, an XBM file is created displaying the new count, and that file is sent to the client. Simple, heh?
 
 

Viewing a Counter Without Incrementing it's Value

If you would like to see the value of a counter without invoking counter.xbm and causing the count to be incremented, then you can use the following URL:
<http://www.lehigh.edu/cgi-bin/counter_text.sh?counter_id">
where counter_id is the unique ID of the counter you want to see. As an example, you can check on the value of the counter shown at the top of this document.