Help Search Campus Map Directories Webmail Home Alumnae Academics Admission Athletics Student Life Offices & Services Library & Technology News & Events About the College Navigation Bar
MHC Home Creating Pages for This Site

Adding Counters to Web Pages

Any page on the MHC Web site can have a hit counter attached to it. The counter keeps track of the number of times the page is accessed, throwing out hits by the same person within a half-hour period. This way the counter is not increased every time someone so much as presses the Reload button in their browser.

Counters have the following restrictions:

  • They may only be used in pages which are on www.mtholyoke.edu or home.mtholyoke.edu.
  • They are numeric only. They do not provide a graphical image.
  • The name of a page to include a counter must end in .htm, .html, .shm or .shtml.

* If you are using the Document Interface in your pages, you will probably find the .COUNTER command easier to use. Please refer to the pages describing the DI for more info.


HTML Code

A counter can be added to any page by simply adding one line of code to an existing HTML page. This is done in the form of a Server-Side Include (SSI) command, which is a special type of comment. Comments must be entered in an editor where you can see the HTML source of a file, that is, the tags like <HEAD> and <BODY>.

A normal comment looks like this:

<!-- This is my comment -->

An SSI comment to invoke the counter looks like this:

<!--#include virtual="/cgi/count.pl"-->

In this case, the #include part tells the Web server that this is an SSI command. The virtual part tells the server what to include, in this case the counter script. In order to use the counter you must always use this syntax, though there are some options that can be added.

By default, the SSI command above produces just the number of hits to the page. You could include it in a HTML file as part of the sentence "X awesome people have surfed this page," like this:

<HTML>
   <HEAD>
      <TITLE>Counter Sample Page</TITLE>
   </HEAD>
   <BODY>
      <H1>Counter Sample Page</H1>
      <P><!--#include virtual="/cgi/count.pl"--> awesome people have surfed this page.
   </BODY>
</HTML>

Click here to see this page in action.


Options

All options are specified by adding a question mark after count.pl. Since the options are all mutually exclusive, there's never any need to specify more than one option at a time.

Since

Using this option, you can display the date at which the first hit occurred. Example:

<!--#include virtual="/cgi/count.pl"--> awesome people have surfed
this page since <!--#include virtual="/cgi/count.pl?since"-->.
20,926 awesome people have surfed this page since April 13, 1998.

Long

This option produces a "canned" version of the full sentence: "This page has been accessed COUNT time(s) since DATE". Example:

<!--#include virtual="/cgi/count.pl?long"-->
This page has been accessed 20,926 times since April 13, 1998.

Quiet

When this option is used, the page count increases but no number is displayed. This is useful when you want to count a page's hits without the reader knowing. You can find out how many hits there have been at a later date by temporarily removing the "quiet" option from the file. Example:

You can't tell, but this page <!--#include virtual="/cgi/count.pl?quiet"-->has a counter.
You can't tell, but this page has a counter.

Reset

To reset the counter to 1 and the "since" date to the current date, the reset option can be used. You should temporarily add the following line of code to your page and then view it using your Web browser:

<!--#include virtual="/cgi/count.pl?reset"-->

When successful, the string [COUNTER RESET] is displayed. Be sure to remove this line of code afterward, or your counter will never increase.


Tips

* To conserve system resources, it is best to only use the counter on the "homepage" of a set of pages. This actually gives a fairly good impression of how many people access your site, since it is usually the place where they enter.

* When testing the counter with a browser, you must go the actual Internet address. You cannot view it by using Netscape's File->Open command or by dragging the file's icon to Netscape.

Home | Directories | Web Email | Calendar | Campus Map | Search | Help

About the College | Admission | Academics | Student Life | Athletics
Offices & Services | Giving | News & Events | Alumnae | Library & Technology

Copyright © 2001 Mount Holyoke College. This page created by the Web Design Team and maintained by Webmaster. Last modified on November 2, 2001.