Note: PageVisits is a Common Gateway Interface (CGI) program written in the Perl language. It requires image processing utilities from the Netpbm image processing toolkit. Installing a CGI program requires detailed knowledge of the Web server configuration of the system on which it is to be installed, and may require administrative (super-user) privilege to install. Programs and data directories must be installed with the correct ownership attributes and permissions, and program and library paths may need to be set to permit the CGI program to find the utilities it requires. Since Web server configurations differ widely from system to system, there's no cookbook approach to installing a program such as this--you need to understand what you're doing, and know how to track down and fix problems based on error messages in the HTTP server error log.It's not an exaggeration to say that most system administrators who can install a program such as this without some difficulty and a few false starts could probably write such a program themselves if they wanted to. The whole point of this program is that they don't have to! This program can serve as a point of departure for those who wish to extend it into something much fancier. It is almost impossible to troubleshoot CGI programs remotely, and even if it were possible, I don't have the time to do so. Consequently, while you're free to use this program in any way you wish without any restrictions, you're entirely on your own--it is utterly unsupported.
pagevisits.tar.gz
Directory | Variable | Example | Location on your system |
---|---|---|---|
CGI binaries | $CGI_Directory | /var/www/cgi-bin | |
Netpbm utilities | $NETPBM_Directory | /usr/bin | |
Perl interpreter | #! | /usr/bin/perl |
./PageVisits.pl testIf you get a "bad interpreter" or "not executable" error, the location of Perl in the first line of the program is probably incorrect or the process of editing the program has caused it to lose execute permission (or Perl is missing or improperly installed on your system). If you get one or more missing directory or file messages, correct the directory configuration accordingly until you get the message "PageVisits configuration test passed.".
# Create counter file and set count to 0 echo 0 >PageVisits/test.dat chown apache:apache PageVisits/test.dat
Visits to this page:
<img src="/cgi-bin/PageVisits.pl?dir=PageVists&pageid=roquefort_ratsauce"
align="bottom" alt="Page Visit Counter">
Test the page and verify that the counter appears and updates each time you reload the page. If you get a "broken image" instead of the counter, look at your Web server's error log to to see what went wrong; almost any error which causes PageVisits to fail will place a message in the log. If your site is so busy that Web server error messages scroll by faster than you can read them (as was the case here during the distributed denial of service attack against Fourmilab in early 2004, you can filter for lines containing the substring "PageVisits" to exclude other error messages.
Once the counter's working, you may wish to adjust its alignment on the page by changing the "align=" specification in the <img> URL, and/or choose a different font (see below) to better conform to your page design.
In the case of a Web counter, the risk consists of a malicious individual with too much time on their hands "running the counter" to inflate its value to absurd numbers in the interest of making it look like you're claiming bogus numbers of visits to your page or, more seriously, using the counter to consume resources on your Web server and thus keep it from processing legitimate requests in a timely fashion (hence, a "denial of service attack").
The best way to guard against this is to bind each counter to the complete URL of the page which references it. Since this URL will contain the name of your site, which is extracted from the page containing the reference to the counter, attackers won't easily be able to "hijack" your counter. To bind the counter to a page on your site, add a second line to the counter data file, after the line with the number of page visits. This line should begin with the string "HTTP_REFERER=" followed by the complete URL of the page which references the counter, for example:
With this as the second line in your roquefort_ratsauce.dat file, references to the counter in other pages on other sites will return a "broken image", neither updating the counter nor consuming resources on the Web server to create the counter image. Messages in the server error log will notify you of the attack, but the attacker won't receive any information which indicates what went wrong. Restricting access to your counter based on the HTTP_REFERER of the page which references it provides only protection against malicious users embedding your counter in other pages or running it up by repeatedly requesting its URL directly.
Note that referer validation provides only a rudimentary degree of security. An attacker who knows enough to forge requests from a browser can circumvent verification of the referring page. But then an attacker could run up your counter simply by requesting reloads of the page which references it over and over in a script. To cope with such attacks, you need comprehensive defence against denial of service attacks like the Invisible Gardol Shield employed at this site. Perhaps some day I'll find the time to adequately document that package, which is dozens of times more difficult to configure and install than PageViews, but when you need it, it's worth it.
Font name | Height | Digits |
---|---|---|
times | 13 | ![]() |
courier | 12 | ![]() |
helvetica | 13 | ![]() |
newsgothic | 26 | ![]() |
brushscript | 23 | ![]() |
curlz | 27 | ![]() |
arabic | 36 | ![]() |
By default, the "times" font is used. To specify a different font, add a "font=" argument to the PageVisits image request URL. For example, to use the courier font, you might specify the following:
Visits to this page: <img src="/cgi-bin/PageVisits.pl?dir=PageVists&pageid=rat_a_tailie&font=courier"
align="bottom" alt="Page Visit Counter">
A font simply consists of ten files, one for each of the digits from 0 to 9, in Netpbm "PPM" format. The digits may be black and white bitmaps, grey scale images, or full colour--regardless of the image type, the file name for a given digit is always the font name followed by the digit with an extension of ".ppm, for example "times4.ppm".
Although the digit images always have an extension of .ppm they may, in fact, be monochrome bitmaps (PBM), grey scale images (PGM), or full-colour (PPM); the digits in a font don't even need to all be the same image type. To save space, save the digit images in the most compact form: if the images are grey-scale, saving them as PGM reduces the digit file size by a factor of three; they're pure black and white bitmaps, saving them as PBM compresses them 24 times compared to PPM format.
After you've made the bitmaps for your new font, it's a good idea to test them to make sure the vertical alignment and spacing between digits looks good. You can override the value of a counter by specifying a "value=number" argument in the request URL, for example:
<img src="/cgi-bin/PageVisits.pl?dir=PageVists&pageid=test&font=myfont&value=1234567890"
align="bottom" alt="Page Visit Counter">
Note that even when you're testing a counter with a "value=" specification the "dir=" and "pageid=" specifications must specify a valid directory and counter file. The value of the counter will not, however, be incremented.
Okay, okay. You can use the following link to download the spider font. Use it wisely.
This software is in the public domain. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions. This software is provided "as is" without express or implied warranty.by John Walker