This script comes as two short
scripts: gcount.pl - the counter code and pass.pl - the
Control Panel
for creating new counters and changing counter values.
This script is mainly intended for
applications where a global count of all pages needs to be displayed on
each page as well as an individual count for each page across an entire
Website or multiple Websites.
It was particularly written for this
site where HTML pages are spread over many physical servers and domain
names.
The code in the counter part is tiny,
making it suitable for sites that get a lot of hits. It worked without a
problem at
over 1,000,000 hits an hour in a concurrent test run on this site during peak
usage. (No we don't get a million hits an hour - it was a simulated test
:)
Parameters
You can install this script in
minutes into your cgi-bin directory of your server. It is called from
within the HTML of your Web Pages by a single line of code with two
parameters:
NUMBER - the number you want the
counter to start at for this page (or default to if something happens to
the counter file) . If you change this number down after the
script has run for the first time, it will not change the count - use
the control panel for this. You can however increase the number upwards
by changing this parameter.
FILENAME - the name of the file in the
cgi-bin folder that will be used to store the value for this counter.
The file cannot be created by the script but only from within the
Control Panel script which is part of the downlaod.
Installation
Change the first line to suit your
servers path to perl. Default is #!/usr/bin/perl
Upload this script IN ASCII!! to a NEW
directory in your servers CGI Directory.
CHMOD the file gcount.pl and pass.pl to 755.
Call gcount.pl (the counter code) from within your HTML
document as follows:
<SCRIPT
language="JavaScript" SRC="http://YourSite.com/cgi-bin/gcountDIR/gcount.pl?NUMBER=FILENAME"></SCRIPT>
Where
NUMBER is an integer representing the
number the counter will start from for this page.
FILENAME is the name of the file in
the CGI directory for this counter.
The Script will not automatically create the counter file. To do this,
you need to call pass.pl (the Control Panel) directly from your Browser
and follow the instructions.
To change the counter value
you can do it two ways:
To make it less you must call
pass.pl directly from your Browser
To make the number more, simply
change the value in the HTML or do it in pass.pl.
(typically use the name of the html
file for the file name e.g. index, newpage, page1 etc) You can install
multiple copies of this counter on a page each calling a different
counter.
For example, if your site has three pages called index.htm, page2.htm
and page3.htm you could do the following:
on index.htm put ..../gcount.pl?100=wholesite as well as
..../gcount.pl?1=index
on page2.htm put ..../gcount.pl?100=wholesite as well as
..../gcount.pl?1=page2
on page3.htm put ..../gcount.pl?100=wholesite as well as
..../gcount.pl?1=page3
You now have two counters on each page showing:
a. The total counts for your website and
b. The count for each page.
The counter at the
bottom of this page uses gcount.pl
Using the Control Panel
Type the URL of the control panel script
into your Browser directly.
e.g. http://yoursite.com/cgi-bin/counterdir/pass.pl
The first time you call the Control Panel, enter your
Admin password twice. This password will be required each time you
create new counters. (if you forget it, you can fix it - see README.TXT).
Type in the name you would like for this counter e.g.
MyPage (note names are case sensitive) and the starting value e.g. 100
and then Click Submit.
Repeat for all pages you want counters for.
At any time, you can come back to the Control Panel
and change the values of any counters.
A future version of this counter will allow for other
customization such as how long since the page was last viewed etc.
(October 2002: The code for that is now included in the download)