This is an example of displaying a visit -- or "hit" -- counter using JavaScript (with a little bit of help from CGI to record the number of visits). This example is from my book The JavaScript Sourcebook, from Wiley Computer Books. Full details of its use appear there.
The visit counter CGI script is a slightly modified version of Counter 4.0, a freeware Perl script by George Burgyan. You can use this script or most any other that can return a numeric (as opposed to graphical) counter value. The Counter 4.0 script was modified as follows.
These lines removed (or commented out using the # character) in "Stage 10" of the script:
print "<a href=\"$nLink\">" if $nLink;
print $count;
print "</a>" if $nLink;
And these were added in their place:
print "<form name=\"counterform\">";
print "<input type=\"hidden\" name=\"counter\" value=\"";
print $count;
print "\">";
print "</form>";
To use the visit counter you must copy the following files (in addition to obtaining the Counter 4 script):
In order to use this example you must install the Counter 4 script on your server, if it is not already, and follow the instructions provided at http://www.webtools.org/counter/. The counter script uses server-side includes, so your server must be set up to handle them. Not all Web sites process server-side includes; contact your Web site administrator if you're not sure about yours.
The counter digits are courtesy of Russ Walsh at Russ's Index Page. A number of other interesting digit images are available there, too.
JavaScript copyright © 1996, Gordon McComb. All Rights Reserved.
Document last updated: February 19, 1997