A Personal Hit Counter () |
|
This hit counter is different, as it attempts to record the number of genuine visitors that visit your web pages. Although installing it requires more effort than with a standard counter, you can be confident in knowing what you are counting, and that you have a flexible counter which is under your control.
Providing the user allows session cookies and JavaScript is enabled, a hit is recorded once per browser session. Otherwise a hit is recorded each time the page is accessed. Hits from all common robot software agents are excluded, and additional robots may be easily added to the list (see Andreas Staeding's site for a comprehensive database of software agents).
Multiple counters are allowed. A counter may be shared across web pages, or limited to one web page; you may have more than one counter on a page; and an unlimited number of web counters may be associated with a web site. A cumulative count is maintained for each counter, and monthly counts are also recorded.
The current count of hits may be optionally displayed on the page.
The main counting software consists of a Perl script, hitcounter.cgi within the server; and a server-side include line and a line of JavaScript within the web page. Because of the server side include, the web pages should have an extension of "shtml".
The Perl script should be held in the server's appropriate cgi bin, and given execute privileges. Counters are held in small text files, one per counter, stored by default in the "/data" subdirectory within the cgi bin drectory. There is a line in the Perl script that allows this relative address to be changed.
my $directory = "data/";
No other changes need to be made to the Perl s cript, although you can also change the hit counter message that is displayed on the bottom line:
my $message = "You are visitor no:";
Within the Perl script, there is a list of user agents which should be ignored, such as search robots and link checkers. All the common ones are included, but if you need to add another agent, they are specified as sets of case insensitive strings separated by the pipe character. In the following example, we are adding three entries to the list held in the string robotlist.
$robotlist = $robotlist . "|googlebot|xenu|scooter";
The following two lines need to be inserted into the web page - typically where the hit counter would be displayed.
<!--#include virtual="/cgi-bin/hitcounter.cgi?counter=countername&display=true"--> <script type="text/javascript">document.cookie = "countername=0";</script>
Note that if your counter is to be used with files stretched across directories, you will need to set the path attribute of your cookie. Thus the following cookie will be shared by all pages within and below the chartreuse directory.
document.cookie = "chartreuse=0; path=/chartreuse";
You may view the total hits notched up for the counters from the hitstats page. This uses a Perl script to generate and display the current state of the hit counters. Selecting one of the individual counters will bring up a further display of all monthly totals recorded for that counter using the web page hitstats1. Both of these scripts should be in the same directory.
The Perl script associated with these displays, hitstats.cgi and hitstats1.cgi, should be held in the server's appropriate cgi bin, and given execute privileges as above. There is a line in the Perl script that allows the subdirectory where the counter files are held to be specified:
my $subdir = "../counter/";
The HTML files contains a line specifying the Perl script. This should be modified to reflect the actual location of the script as above:
<!--#exec cgi="../cgi-bin/webstats.cgi"-->
Download Zip File (12 Kb).