|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/toc/cgi-bin/ |
Upload File : |
#!/usr/bin/perl
#^-^-^-^-^-^-^-
#
# 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="http://www.jaustinforbes.com/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 = "images/digits/A/";
# $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