Adding an Access Counter
A text access counter
The Increment subroutine
The complete text access counter script
Seeding the Counter
Adding the Counter to Your HTML Page
With Server Side Includes
Without Server Side Includes
Creating the Template File
Modifying the access.pl Script
A graphical access counter
Incrementing the Counter
Creating the GIF Image
Returning the Graphical Counter Image
The Graphical Counter Script
Calling the Counter with the <IMG> Tag

[Previous] [Next]


A text access counter


The text access counter displays the count number in plain text within the HTML page. Figure 1 displayed several text and graphical access counters. Because the text counter uses plain text, it is much easier to implement than a graphical counter. The biggest decision is how to call the access counter script. It's easiest to do this with Server Side Includes, but not all systems have Server Side Includes enabled. The following sections describe how to create the text access counter script and explain two different ways of adding it to your Web pages.

Creating the Counter Script

Before starting your CGI script, you should spend a moment thinking about what it must do. The script needs access to the current value of the access counter. For this information to be available, you must store it in a text file. Every time your text access counter script is called, it opens the counter file in which the current access count is stored, increments the access count, and saves the new number in the counter file. After the counter value has been incremented, the number is included in the Web page.


[Previous] [Next]