Adding Counters To Your Web Pages


This page presents a simple method for adding counters to your web pages. Its advantages are: Of course, it has some disadvantages: Here is the method I used:

Take the html file on which you want the count to appear, and break it into two files at the point where you want the count to appear. I named these files welcome.pt1 and welcome.pt2.

Create a script file like this:

#!/bin/bash
#
# These lines get your current count value, increment it, then
# write it back to the count file. You can setup several count
# files if you want, with separate scripts
#
C=`cat /www/cgi-bin/count`
C=$[$C+1]
echo $C > /www/cgi-bin/count
#
# These lines build your page using the pieces you saved, plus the
# count file value. More than two pieces can be used, and other
# data besides counts can be inserted (like dates, etc).
#
cat /www/welcome.pt1 > /www/w.html
echo $C >> /www/w.html
cat /www/welcome.pt2 >> /www/w.html
#
# These lines direct the browser to use the new page you just built.
#
echo "Location: http://citynight.com/w.html"
echo

Put the file in your cgi-bin directory. (If you have not yet set up a directory for exec scripts, refer to the Cern httpd documentation.) I called the file welcome.sh.

Initialize your count file: echo "1234" > count. You can use zero, or you can count lines from your httpd log to see what the count should be started at.

Make sure you have the following line in your httpd.conf file. Send a -HUP signal to httpd if you make any changes.

Exec	/		/www/cgi-bin/welcome.sh

Make sure the new files have the correct permissions. HTTPD must have read access to all the files, write access to the count file, and execute access to the script.

Give it a try.
Visit The City Of Night BBS Home Page.