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
With Server Side Includes
As mentioned, it's easiest to implement your text access counter using Server Side Includes. Simply choose which Web page you want to display your counter and add some surrounding text and the following Server Side Include:
<!--#exec cgi="/cgi-bin/access.pl" -->
If Server Side Includes are enabled on your Web server, the Web server will parse this line before sending it to the user's Web browser. The CGI script access.pl is executed and the output from the script is substituted for the preceding line in the HTML.
For example, the following HTML code demonstrates how to add the Server Side Include statement to your existing HTML page:
<HTML> <HEAD> <TITLE>Example of Text Access Counter</TITLE> </HEAD> <BODY> <H1>Text Access Counter</H1> This is my Home page. Thank you for visiting. Please come again. <P>This page has been accessed <!--#exec cgi="/cgi-bin/access.pl" --> times. </BODY> </HTML>
As you can see, the Server Side Include was added along with some surrounding text to explain what the number represents. The surrounding text is "This page has been accessed x times." The x represents where the Web server would insert the value returned by your access.pl script. Figure 2 shows how the HTML page will appear when the access count is 13.

Figure 2: The text access counter