A Playground of Thoughts > A Counter Program

A Counter Program

This page explains how to use a counter program which allows you to use your own GIF files for digits.

You can test the program with the following form:


The Number value must be a nonnegative number. The Format value must be a positive number enclosed by "!0" and "d". The number means the number of the total digits the program will show. If your know C, consider "!" as "%" in the printf function. I use "!" because "%" cannot be used in URL names. Click the OK button and you'll get a GIF file which contains the number you specify.

To use the counter, there must be Perl in your homepage server. It should be either "/usr/bin/perl" or "/usr/bin/local/perl". Ask your provider where Perl is. The version of Perl must be 5.0 or higher.

You need to install the following files:

  1. Perl programs.
    There are three files to install.
    counter.cgiThe main program. Save it to the disk as "counter.cgi" .
    gifinput.plA GIF reader.
    gifoutput.plA GIF writer.

  2. Digit GIF files.
    You need GIF files for 0 through 9. Their names must be "ac0.dat" through "ac9.dat". I found the following files in Digit Mania, which has a nice collection of digit GIF files.

    Download these files if you want a quick start.

  3. A server control file.
    For the server to distinguish programs from ordinary files, the file .htaccess is necessary. If you have already installed a program in your site, possibly you don't need it. If you haven't, install it together.

If your homepage server doesn't have Perl as "/usr/bin/local/perl", you have to modify the first line in the file counter.cgi . Suppose the position is "/usr/bin/perl", and you need to modify the first line as this:


You also need a counter file which contains an access count. Create a text file named ac.dat, and write only "0" in it. That means there has been no access before.

Now you can install them onto your homepage server. I explain how to install with ftp from a command line.

First, connect with ftp to your homepage server, for example "www.sf.airnet.ne.jp".

ftp www.sf.airnet.ne.jp

Type your user name and password to enter.

Please note that your homepage directory might not be your home directory (the starting directory for ftp). Use the cd command in that case. For example, if your homepage directory is "public_html" in your home directory, you need to type the following command:

cd public_html

If you need to install .htaccess, type the following command:

put .htaccess

Then create a directory in your homepage directory and go to the directory.

mkdir counter
cd counter

Then install Perl programs and the counter file.

put counter.cgi
put gifinput.pl
put gifoutput.pl
put ac.dat

Use the bin command to change the mode binary in order to install the digit files.

mput ac?.gif

Now that you have sent the files, modify the file attributes to make them work as a program, and disconnect.

site chmod 666 ac.dat
site chmod 755 counter.cgi

If you have a problem with the site command, use the quote command like this:

quote site chmod 666 ac.dat
quote site chmod 755 counter.cgi

You have installed all the files. Write the following sentence in your web page (possibly "index.html") and you'll get the counter.

<IMG SRC="counter/counter.cgi?up=1" WIDTH=75 HEIGHT=27 ALT="Counter"><BR>

The program can have the following parameters:

formatThe number format. The default value is "!05d", which means five digits.
counterThe counter file. The default value is "ac.dat".
imageThe digit files. The default value is "ac!d.gif", which means "ac0.gif" through "ac9.gif". If you want to use other files, say "counter0.gif" through "counter9.gif", specify "counter!d.gif".
upIf it is defined and is not 0, one is added to the counter. The default value is 0, which means there will be no addition.

If there are more than one parameter, insert ";" (semicolon) between them, such as "counter/counter.cgi?up=1;format=!06d" .

The WIDTH and HEIGHT parameters depend on the GIF files and the format. In the example shown above, the total width is 180 and the height is 47, because each digit file has a width of 36 and a height of 47, and there are five digits. You can omit these parameters, but web browsers can show your page faster if they are provided.

Return to my homepage

Copyright(C) TAKASUGI Shinji (tssf.airnet.ne.jp)