Make your own free website on Tripod.com

VersaCounter

This is a very versatile counter. (Hence, its name...) It can be used with Server Side Includes (SSI) or by a simple HTML image tag. The SSI method allows for more display options, such as plain text output, which can then be manipulated by the HTML markup of the web page. On the other hand, the image tag method can be used to put counters in HTML documents residing on remote web sites. You can even embed a VersaCounter in virtual HTML documents produced by other CGI scripts.

Features include:

With SSI operation the script outputs ordinary text/html to the server, which then parses it into the web page. For the text counter style this output is plain text, with an optional preset hyperlink around the hit count. The text style is very handy , since ordinary HTML markup can then be used to change the font. (See the examples below.) For the graphical counter styles (LED, odometer, ...) the script replaces the hit count with an HTML image tag pointing to the GIF image of the counter, saved as another file on the server.

For the graphical counter styles the single counter image is created from individual images of the counter digits. Each digit style is contained in a separate subdirectory (of the same name as the style). Hundreds of digit styles are available from the Digit Mania archive. New styles can be added at any time by simply placing them in the proper directories.

For non-SSI operation an HTML image tag can be placed in the web document pointing to the VersaCounter script. The GIF image of the counter is then output directly to the browser. In this mode of operation, the text style is unavailable.

When logging is enabled a log file is created for each HTML document. This contains the time/date, remote host, referring page (SSI only), and user agent/platform associated with each hit. I am currently working on a site statistics program which utilizes these logs. Here is a demo of the current program.

How to Get it!

VersaCounter is free for personal, non-profit use only. (Licenses for commercial use or reselling of the program may be arranged by contacting the author.) The program is a single CGI script written in Perl, requiring version 5.004 or higher. It uses flock() for the counter and log file locking, the CGI.pm Perl module to handle CGI requests, and the GD.pm graphics library to construct the GIF images. (The latest version of GD.pm is available from CPAN. You do not need root privaleges to install it.)

Here is the gzipped tarfile containing the Perl script, digit images, and installation instructions.

Use in HTML Documents

with Server Side Includes:

<!--#include virtual="/path/vcounter?option1=value1&option2=value2... " -->

path is the directory path from the top of the web site to the VersaCounter script, with filename vcounter (change to vcounter.cgi as necessary). The available options are

optionsdefaultspossible values
page URLname or if unspecified, the URL of the page is used (with /'s changed to _'s)
show countercounter, date, all ("<counter> hits since <date>"), nothing
style texttext, odometer, LED, ... names of the installed digit directories ...
digits 0N - minimum number of digits to display
trans - r,g,b - color number to make transparent (r,g,b each run 0 ... 255)
link 00, 1 - turn off, on the preset hyperlink
align bottomtop, middle, bottom - alignment of text after graphical counter image
block 360sec - number of seconds to block consecutive reloads from incrementing
increment 10, 1 - turn off, on counter incrementation ("counting")
log 10, 1 - turn off, on logging of visitor statistics
start 0count - initialize counter to start at the value count *
start_date creation date - initialize counter as if started on date (any format) *
* these options only need to be supplied upon initial creation (if ever)

Examples of SSI Use:

  1. Simple graphical counter:

    <!--#include virtual="cgi-bin/vcounter?style=odometer" -->

    Counter Image

  2. Simple text counter:

    <B> Welcome! <B> You are visitor number <!--#include virtual="cgi-bin/vcounter?style=text" -->.

    Welcome! You are visitor number 4,710,532.

  3. Display both the count and date of initialization:

    <!--#include virtual="cgi-bin/vcounter?style=text&show=all" -->

    4,710,532 hits since May 31, 1998

  4. Adding the preset hyperlink and removing commas:

    <H1> <!--#include virtual="cgi-bin/vcounter? style=text&commas=0&show=all&link=1" --> </H1>

    4710532 hits since May 31, 1998

  5. Using counter and initialization date separately:

    <FONT SIZE="5">
    <!--#include virtual="cgi-bin/vcounter? show=counter&style=text&link=1" -->
    </FONT> < BR >
    <I> visitors since <!--#include virtual="cgi-bin/vcounter?show=date" --> </I>

    4,710,532
    visitors since May 31, 1998

  6. Using graphical counter and initialization date separately:

    <!--#include virtual="cgi-bin/vcounter?show=counter&style=rosewood" -->
    <FONT SIZE="7">satisfied customers</FONT>,
    since <B> <!--#include virtual="cgi-bin/vcounter?show=date" --> </B>

    Counter Image satisfied customers, since May 31, 1998

without Server Side Includes:

<IMG SRC="http://www.wherever.com/path/vcounter?option1=value1&option2=value2... ">

Here, www.wherever.com is the hypothetical name of the server running the VersaCounter script. The available options are

optionsdefaultspossible values
page URLname or if unspecified, the URL of the page is used (with /'s changed to _'s)
show countercounter, nothing
style odometerodometer, LED, ... names of the installed digit directories ...
digits 0N - minimum number of digits to display
trans - r,g,b - color number to make transparent (r,g,b each run 0 ... 255)
block 360sec - number of seconds to block consecutive reloads from incrementing
increment 10, 1 - turn off, on counter incrementation ("counting")
log 10, 1 - turn off, on logging of visitor statistics
start 0count - initialize counter to start at the value count *
start_date creation date - initialize counter as if started on date (any format) *
* these options only need to be supplied upon initial creation (if ever)

Examples of IMAGE TAG use:

  1. Simple odometer style:

    <IMG ALT="Counter Image" SRC="cgi-bin/vcounter?style=odometer">

    Counter Image

  2. LED style and specifying 10 digits:

    <IMG ALT="Counter Image" SRC="cgi-bin/vcounter?style=LED_green&digits=10">

    Counter Image

  3. Adding a hyperlink:

    <A HREF="http://www.aquilo.net/stats.cgi">
    <IMG ALT="Counter Image" SRC="cgi-bin/vcounter?style=curly">
    </A>

    Counter Image

Using VersaCounter in Virtual Web Pages

You can put a counter on a virtual web page produced by another CGI script, by either printing out an HTML image tag (like those above), or by explicitly calling VersaCounter from the other script. Either way the CGI script the counter is embedded in will output the HTTP header to the server. Therefore, the usual HTTP header output from VersaCounter will have to be suppressed. This is achieved by passing the additional header=0 option to VersaCounter. Here are some examples in Perl:

Printing an HTML image tag:

     #!/usr/bin/perl

     print "Content-type: text/html\n\n";               # output http header
     print "<HTML>\n";
     print "<HEAD><TITLE>Virtual Web Page</TITLE></HEAD>\n";
     print "<BODY>\n";
     print "Hello, you are visitor number"; 
     print "<IMG SRC=\"/cgi-bin/vcounter?style=odometer&header=0\">\n";
     print "</BODY>\n";
     print "</HTML>\n";

With this method the counter works the same as in normal non-SSI operation. Hence, no text output is available. A better method is to emulate SSI operation, as in the following example.

Explicit system call:

  #!/usr/bin/perl

     print "Content-type: text/html\n\n";               # output http header
     print "<HTML>\n";
     print "<HEAD><TITLE>Virtual Web Page</TITLE></HEAD>\n";
     print "<BODY>\n";
     print "Hello, you are visitor number"
     {
     local $ENV{'DOCUMENT_URI'} = '/cgi-bin/$0';             # pass page name
     local $ENV{'REQUEST_METHOD'} = 'GET';                   # ensure GET method
     local $ENV{'QUERY_STRING'} = 'style=odometer&header=0'; # pass counter options
     print `/usr/local/www/cgi-bin/vcounter`;                # call counter
     }
     print "</BODY>\n";
     print "</HTML>\n";

As in SSI operation, all VersaCounter options are now available.


chavel@aquilo.net