It is currently Thu Mar 28, 2024 8:51 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: OK, where is the logic error?
PostPosted: Wed May 10, 2006 12:52 am 
Noobie
Noobie

Joined: Wed May 10, 2006 12:42 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 4:42 am 
I have no life!
I have no life!

Joined: Sun Feb 13, 2005 6:12 pm
Posts: 1504
Location: My Office
Sorry, I am no CGI Developer / Coder. So I can not help you out. :cry:

_________________
Best Regards:
Aaron McGowan (aka: CyberGeek, =cipher=)

CyberGeek's Software Solutions
-- WWW: http://www.cybergeeksoftware.com
-- Tech Line: 1-519-860-4557
-- Email: cybergeek@cybergeeksoftware.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
100WebSpace © 2011