CGI Wysardry
Installing Perl CGI Scripts

Installing the Data2Design Multi-hit Counter script at Spaceports.



Home / CGI / Multi-hit Counter

Back | Next

Overview

This page gives instructions on how to adapt the Multi-hit Counter script from Data2Design for use on Spaceports.

This simple counter can keep track of multiple pages on both servers without the need for SSI.

Unfortunately, if you don't already have it, getting hold of the program may prove difficult as the Data2Design site no longer offers Perl scripts.

I am leaving these instructions in place for those of you that already have the program, or know where to obtain it.


Before you start

Read the Readme file!

Decide where you are going to put your counter - I suggest using the following directory structure:-

/multihit/ - the main counter directory.
/multihit/data/ - where the log file and counter digits are stored.

If you wish to put yours elsewhere, you will have to change the paths accordingly.


Path change

If you signed up for your CGI-BIN account after the end of July 2000, but before the middle of February 2002 you will need to change all references to home in the paths to home2 or the script will not work.

If you received your CGI-BIN account after the middle of February 2002 you will need to change all references to home in the paths to home3 to avoid errors.


multi-hit.pl

Remembering to change username to your username, and the directory structure to match your own, use the example below as a guideline:-


# Configuration

use CGI;
use CGI::Carp qw/fatalsToBrowser/;

$HIT_FILE="/home/username/public_html/multihit/data/mhits.txt"; # file where hits are located.
$PIX_DIR="/home/username/public_html/multihit/data/"; # All numbers are marked 0 - 9 plus a blank.


That is all that needs to be changed.

You will also need to create an empty text file called mhits.txt to avoid possible problems with the script creating it.


Uploading

Here are the steps involved:-

  1. Create the necessary directories.
  2. Upload multi-hit.pl in ASCII mode to the multihit directory.
  3. Upload mhits.txt in ASCII mode to the data directory.
  4. Upload the .gif files in Binary mode to the data directory.
  5. CHMOD the multihit directory and multi-hit.pl to 755
  6. CHMOD the data directory and all files inside to 777

The HTML

To include the counter on your page you will need to use code similar to the following:-


<!--begin multi-hit hit counter-->
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?6=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?5=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?4=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?3=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?2=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?1=index" width="12" height="20">
<img src="http://cgi-bin.spaceports.com/~username/multihit/multi-hit.pl?0=index" width="12" height="20">
<!--end multi-hit hit counter-->


Note the use of the full URL in the path.  That allows you to use the counter on either the CGI-BIN or the standard server.  Remember to call the script with a unique name for each page for an accurate count - replace index with a different word for each page.

It might be an idea to prefix names for pages on your planet server with the word web and the ones on the CGI-BIN with cgi to help keep track of them all.  For instance, the name used for the main index page on your 'planet' server could be web_index and for the main page for your CGI-BIN could be cgi_index.

You can use whatever naming convention suits you though, as long as you don't use any strange characters or make them too long.


The result

If all went according to plan, your counter should be ready to use. If you want to see an example of it in use, here it is:-

Counter

Please note that by default this counter displays leading blanks, not leading zeroes.  If you would prefer to have leading zeroes, the easiest way to do this is to have a copy of 0.gif renamed as blank.gif uploaded.

Site Menu

Sell t-shirts with your design ... for free!

Section Menu


Copyright © 2000-2003 Wysardry

Most recently updated on 11 May, 2003

Home / CGI / Multi-hit Counter

Back | Next


Please feel free to contact us with any comments or suggestions
Installing Perl CGI Scripts
CGI Wysardry

This site is hosted by Spaceports