Counters, counters everywhere! It seems that the hit counter is just about as ubiquitous as the web itself! Two simple counter CGIs, one text and one graphical, are presented in the sections below. The text counter was written by Jonathan Lewis. The graphical counter is simply a modification of the textual counter by Scott Pierce.

Installation

To install the counters, connect to your Virtual Private Server via Telnet or SSH and use the following command:

% vinstall counter

Configuration

To configure the counters, do the following.

  1. Configure your Virtual Private Server web server to recognize Server Side Includes. Do this by creating a file called .htaccess in the same directory where the page with the counter is to reside. The .htaccess file should contain the following lines.

    Options Indexes FollowSymLinks Includes ExecCGI
    AddHandler server-parsed .html

    You can either use the pico file editor to create the file on your Virtual Private Server or you can create it locally on your own PC (using notepad, for example) and then use an FTP client to upload it to your server (in ASCII mode).

  2. Initialize your counter with a start value. Do this by creating a file with the same basename as your .html file that you plan to put the counter on, but with the extension .count, instead of .html. For example, for a filed called index.html, create a file by the name of index.count. Put this file in the same directory as the index.html file. The .count file will contain just one number: the value from which you want your counter to begin (probably 0).

    You can create the .count File locally on your own PC and then use an FTP client to upload it to your server (in ASCII mode). Or you can do this while connected to your server by doing the following from a SSH or Telnet prompt.

    % cat > index.count
      0
    ^D (the control-D character)

Usage

Now you are ready to implement your new counter. Place the counter server side include in the HTML of the page on which you want to have a counter. In the .html file include something like the following in the main body of HTML.

Textual Counter
<!--#exec cgi="/cgi-bin/library/counter/c4.pl" -->

Graphical Counter
<!--#exec cgi="/cgi-bin/library/counter/c4g.pl" -->

Reload your web page and see if it works. Once you have completed the installation successfully, you will have a working counter like the one shown below (simulated).

Over   102060   Internet Customers Served.

Graphical Counter Digit Sets

You have the flexibility of specifying a graphical counter digit set to be used to display the count if you are using the graphical counter. Several Digit Sets are included in the distribution. To use any of these digit sets, set the $digit_path, $digit_width, and $digit_height variables as indicated. You will find the declaration of the $img_path, $digit_width, and $digit_height variables in the c4g.pl CGI on lines 9-11.

Many other digit sets are available. The definitive site for graphical digit sets is Digit Mania Have a look at the hundreds (literally) of digit sets available. If you find a digit set that you would like to use, it is a very simple procedure to configure the c4g.pl CGI to use your preferred images. Just follow these steps:

  1. Make a directory in the ~/www/htdocs/images/digits directory called SOME-NAME.

  2. Place the 10 images, 0.gif, 1.gif, 2.gif, etc., in the new directory, ~/www/htdocs/images/digits/SOME-NAME.

  3. Set the $digit_path, $digit_width, and $digit_height variables appropriately. These variables are defined on lines 9-11 in the c4g.pl CGI.

Docmumentation

Each counter is documented within the source code:

For technical documentation of CGI, see:

Please note: the information on this page applies to ITS web hosting plans. It may or may not apply to other environments. If you are looking for a feature described here, or better support from your hosting provider, please consider hosting your site with ITS!

1555 N Naperville/Wheaton Road, Suite 107
Naperville, IL 60563
phone 630.420.2550
fax 630.420.2771