The script is called by your HTML code in the page being counted, and the output file is named there. Because you control the name of the file that is created with the count, you can use the same script to count multiple pages just by specifying a different output file. This also allows you to cheat. Here's the script, which can also be retrieved by FTP.
#!/bin/ksh # This script creates a file showing the number # of times it has been executed. Useful for # background counts of html accesses and the like. # Written by Jay Hennigan (jay@west.net) # Released to the public domain 1996. echo typeset -i counter=1 outfile=../public_html/$1 if test -s $outfile then read counter < $outfile counter=$counter+1 fi echo $counter > $outfileYou will need to place the above code into a directory labeled
cgi-binimmediately under your home directory. You can either
mkdir cgi-bin chmod 711 cgi-bin cd cgi-bin cp /home1/ftp/pub/staff/jay/count count chmod 711 count
<!--#include virtual="/cgi-bin/cgiwrap/username/count?filename"-->
Substituting your own username for username above, and also substituting a filename such as page.hits for filename above. If you're counting multiple pages, each one should have a unique filename.
For example, the code that counts this page is:
<!--#include virtual="/cgi-bin/cgiwrap/jay/count?countpage"-->
You also need to make the page to be counted executable. To do this, run the following unix commands, assuming that the page to be counted is page.html .
cd public_html chmod 755 page.html
It isn't necessary to display the count at all, bear in mind that such displays will slow down the access to your page, and may not be accurate if the page is cached. As a rule the count is more interesting to you as the author than to the reader. If you choose not to display the count, you can always go to your public_html directory and read the file page.hits .
To display the count on a web page, we can include the file in a line of text, like this:
The page page has been accessed <!--#include file="page.hits"--> times.
For this page, this yields:
The page you're reading has been accessed
8179
times.
