Counters or Odometers typically are simple shell or perl scripts that update a file each time the page is accessed. They run as Server-Side Includes (SSI) that execute automatically when the page is accessed. Before you try to install a counter you need to know a few things.
First, your ISP must allow cgi's and SSI's for you to have a counter.If they don't, find a better ISP. And Second, the shell or perl script that executes must be in the correct directory. Here at
Postino, the Best ISP in Canada, they want us to put our HTML in a sub-directory of our home directory called public_html, and our cgi's into a subdirectory of that, called cgi-bin. Some ISP's require that the cgi's be in their public cgi-bin directory.
Some ISP's even provide the script for you. Check with them.
Now that we have the preamble out of the way:
<P>You are visitor Number <!--#exec cgi="cgi-bin/counter.cgi"-->
This will tell the server to execute the program counter.cgi,(which is in the cgi-bin directory) and put the output into the HTML Document. It is important that the script have permissions 755. The script that is executed is:
#!/usr/bin/perl $FileName = "hit.count"; # this is the file were the count is kept print "Content-type: text/html\n\n"; open (COUNT,"<$FileName") || die "Cannot open $FileName" ; $accesses=<COUNT>; # read in last count $accesses++ ; # Increment the access count print $accesses ; # print out the new count close(COUNT) ; open (COUNT,">$FileName") ; # open for output print COUNT $accesses ; # update the file hit.count close (COUNT) ; # close & exit
To have this work, simply put the sample line into your HTML document and put the script into your cgi-bin directory. Create the log file in the same cgi-bin directory with : #touch hit.count (cr) and set the proper permissions with : #chmod 755 counter.cgi (cr) #chmod 777 hit.count (cr)
Have a Question or Suggestion? Drop Me An
And Tell Me!
Back to Danny's CGI Page
Sponsored by Postino Dotcom