I took an online class in CGI years ago. The code given below is a script that did work on the school server. I modified it for COOLINC.INFO. I created a cgi-bin folder and placed this file in that folder. I use test files to check the script. While there are no errors reported, there is no display of the page count. Can anyone give me an idea as to what is wrong with this script?
Thanks
Code:
#!/usr/bin/perl -w
#^-^-^-^-^-^-^-
#
# Change the first line based on your questionnaire to make
# file call the Perl interpreter
#
# vcount.cgi
# Simple Page counter script
# v1.0
#
# Copyright by Chris Baron
# 1997 All Rights Reserved
# written for
# the Addison-Wesley Book
# Drag 'n Drop CGI: Enhancing your Web Site Without Programming
#
# calling format is
#
# <!--#exec cmd="/cgi-path/addcount.cgi command [pgname [gr]]"-->
#
# Where command is:
#
# pgname - the name of a Page to appear in the count summary table
#
# reset - resets the counts to zero and updates the master date record
# resets count for all pages
#
# disp - if alone, display a table with all page counts and the time the
# count was last reset
# if with a pagename, increment and display the count for that page
# if with pagename gr, use graphical digits otherwise use text
#
####################### Configuration Block ##############################
# $cntfile
# where you want to store the page counts
# use the path to your web directory from your questionnaire
# then put it in a directory accessible by the web server i.e.
# in a file or sub-directory beneath where your home page resides
# remember UNIX uses / and NT uses \
# example: $cntfile = "/home/cbaron/www/cgi/pgcount";
$cntfile="/home/www/calpro.coolinc.info/cgi-bin/pgcount";
# $digit_dir
# path to the directory containing the digit images
# be sure to put a / or \ on the end
# example: $digit_dir = "/home/juser/public_html/images/digits/TypeA/";
$digit_dir = "/home/www/calpro.coolinc.info/digits/";
# $pre_digit
# a string to print before each digit of the count
# this is optional
# example: $pre_digit = "<TD>"; (to put it in a table)
$pre_digit = "";
# $post_digit
# the mate to the above to print after each count digit
# also optional as above
# example: $post_digit = "</TD>";
$post_digit = "";
# $length
# how many digits you want to include in your counter
# optional if you don't want extra zeros leave commented out
# example $length = 10 # gives 0000000001 as your first count
$length = 5;
######################## End Configuration Block #########################
# a standard Perl library for printing time & date
require 'ctime.pl';
@nums = ('zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine');
$cmd = $ARGV[0]; # arguments passed from the SSI call
$qs = $ENV{'QUERY_STRING'}; # arguments passed from a hyperlink
dbmopen(%counters, $cntfile, 0666); # open the counter file
if (($qs eq 'reset') || ($cmd eq 'reset')) {
foreach $pg (keys(%counters)) {
$counters{$pg} = 0;
}
$counters{'date'} = &ctime(time);
print "Content-type: text/html\n\n";
print "<HTML><BODY><P>Counts Reset</BODY></HTML>";
}
elsif ($cmd eq 'disp') {
if (! defined($ARGV[1])) { # disp alone
print "<CENTER><TABLE BORDER=2>";
print "<TR><TH colspan=2>Count Started on";
print " $counters{'date'}</TH></TR>\n";
print "<TR><TH>Page</TH><TH>Visits</TH></TR>\n";
foreach $pg (sort keys(%counters)) {
if ($pg ne 'date') {
print "<TR><TD>$pg</TD><TD>$counters{$pg}</TD>\n";
}
}
print "</TABLE></CENTER>\n";
}
else {
if (defined $counters{$ARGV[1]}) { # display for a page
$counters{$ARGV[1]}++;
$visits = $counters{$ARGV[1]};
}
else {
$counters{$ARGV[1]} = 0;
$visits = ++$counters{$ARGV[1]};
}
while ($visits > 0) {
unshift(@digits, $visits % 10); # mod 10 gives 1s digit
$visits = int($visits / 10); # dump fraction
} # @digits array now holds all the digits in our count
# add padding if desired
if (defined $length) {
while ($length > scalar(@digits)) {
unshift(@digits, 0);
}
}
if (($ARGV[2] eq 'gr') || ($ARGV[2] eq 'GR')) { # use graphics
while (@digits) {
$digit = shift(@digits);
print qq($pre_digit<IMG SRC="$digit_dir);
print qq($nums[$digit].gif">$post_digit\n);
}
}
else { #use text
while (@digits) {
$digit = shift(@digits);
print "$pre_digit"."$digit"."$post_digit";
}
print "\n";
}
}
}
else {
if (! defined $counters{$cmd}) {
$counters{$cmd}=1;
}
else {
$counters{$cmd}++;
}
}
dbmclose(%counters);
# end of vcount.cgi