#!/usr/bin/perl --
require 5;
# COPYRIGHT NOTICE
#
# MULTI-HIT Hit Counter
# (C) 2000, Christopher Shannon
#
# This script may be used free of charge, but may not be sold without the
# express permission of the author. You are free to modify the script
# for your personal use, but you may not copyright any code based on
# the code herein. Or if you use portions of the script in any other code,
# you may not copyright those portions of the code.
#
# No technical support for this code is given. (Hey, it's a freebie.)
# Please report any bugs to
#
# cshannon@mdo.net
#
# URL: http://www.data2design.com
#
# For further inquiries for scripting, please contact the author at the
# above e-mail address, or phone (410) 528-5315 (in the USA).
# PURPOSE
#
# Multi-Hit Hit Counter is a script which allows a user to set a counter
# on several pages on his/her website that all refer to only one script.
# This was developed out of frustration with the many 1-hit-counter-to
# -1-script type of scripts in various script archives. If you have
# two web pages that needs a script, then you have to make a copy of
# the script, rename it or put it in another directory, and reconfigure it.
# Multi-Hit is a solution to this problem.
# TESTING
#
# This script has been tested on WinNT40, service pack 4 running Apache, and
# on Redhat Linux 6.1 running who0-knows-what--both running Perl 5.005_03
# -------------#
# INSTRUCTIONS #
# -------------#
# PLACING THE HIT COUNTER IN YOUR DOCUMENT
# Here is an example of a properly configured hit-counter:
#
#
#
#
#
#
#
#
#
#
#
# EXPLANATION
#
# Your counter is actually calling a perl script that is piping a gif file
# to your browser. This is done by placing the location of the perl script
# in place of where you would normally specify an image. For example,
#
# instead of
#
# you would specify
#
# and that will call the perl script which will send the gif file to
# your browser. Now, notice that appended to the name of multi-hit.pl
# is a funny looking combination of characters. These characters define
# additional information needed by the script to understand which digit
# to send to the browser. These characters designate the right-most digit,
# starting with 0 For example:
#
# 6 5 4 3 2 1 0
#
# Represents the order, from left to right the number, as it will appear. If
# you have a 4 digit hit counter, then the order of the numbers will be
#
# 3 2 1 0
#
# To set up a four-digit hit counter, you would do the following:
#
#
#
#
#
#
# The syntax is
#
# multi-hit.pl?X=any_name
#
# Where "multi-hit.pl" is the name of the script. "?" designates the
# start of the additional information used by the script. Then you
# specify a number which will be a digit. All the number have to start
# from 0. Even if you have a 1 digit counter, you must start from 0,
# otherwise the script won't work. So, the rest of this code snippet
# is
#
# ?X=any_name
# ^^^^^^^^
# Any name you want goes here (try to avoid funny characters).
#
# In human terms, read
#
# Question-mark, then any digit in place of X, equals a particular name.
#
# Make sure that your names are unique for each page you use this counter with.
# Multi-hit records all the hits for all the pages in one file.
#
# With regard to the rest of the parameters, make sure the width and height
# in the field corresponds to the dimensions of your counters.
# The examples above use the same dimensions of the gif files that come
# with this script.
# SETTING UP THE SCRIPT
# On the very first line (above), put the location of your perl interpreter.
# Do this by placing #! and then the perl interpreter's path.
# If you are not sure where your perl interpreter is, then ask your
# system administrator.
#
# The next thing is to specify the location of HIT_FILE. HIT_FILE
# keeps track of all the numbers of all the pages that access
# this script. After selecting a directory, designate an empty
# file and enter the name and path in the following way:
#
# $HIT_FILE="/my_path/on/the_web/my_hit_stats.ext";
#
# or use any other such name for your file.
# If you are using unix/linux, make sure you chmod 644 or chmod 666
# your file so the program can write to it. On WinNT, make sure
# it is in a directory with read/write access.
#
# The next directory to configure is $PIX_DIR, which is the location
# of all your gif numbers. You should have numbers 0 - 9 plus a
# blank counter for digits which you have not yet reached. Place
# all these files in a directory, and enter the path of that directory
# as follows:
#
# $PIX_DIR="/my/pictures/";
#
# NOTE: MAKE SURE YOUR LINE ENDS WITH A SEMICOLON.
# If you are not sure what the path/location of your directory
# on your site is, if you are telneting in, go to your directory
# and type
#
# pwd
#
# And that will tell you where the server thinks you are.
# If you are using an FTP client, there is usually a corresponding
# command in your utility.
#
# All your numbers should be gif files, should be uniform in size,
# and I recommend using only two colors and specifying that the
# background is transparent. This way whatever cool background
# you choose for your site will not be blocked out. Here are the
# files you should have:
#
# 0.gif
# 1.gif
# 2.gif
# .
# .
# .
# 9.gif
# blank.gif
#
# Note, if you name your blank.gif BLANK.GIF or use caps anywhere,
# it won't be recognized on a unix/linux system because the file
# system is case sensitive--be careful.
#
# And finally, on unix/linux systems, make sure this file is chmod 755
# so it can execute.
# Configuration
$HIT_FILE="/var/www/users/imf/public_html/counter/counter.txt"; # file where hits are located.
$PIX_DIR="/var/www/users/imf/public_html/counter/"; # All numbers are marked 0 - 9 plus a blank.
# DO NOT CHANGE ANYTHING BELOW THIS LINE.
undef $/;
$qs=$ENV{QUERY_STRING};
@pr=split /=/, $qs;
$ord=$pr[0];
$f_name=$pr[1];
sub get_listing {
open LIST, "<$HIT_FILE";
$lst=;
close LIST;
my $fnd=$lst=~/$f_name=(.*?)\n/s;
unless ($fnd) {
return 1;
} else {
return int($1);
}
}
sub set_listing {
$cur_num=int($cur_num) + 1;
my $fnd=$lst=~s/($f_name=)\d+/\1$cur_num/s;
if ($fnd == 0) {
$lst=$lst."$f_name"."=2\n";
}
open OUT, ">$HIT_FILE";
print OUT $lst;
close OUT;
}
$cur_num=&get_listing;
@digits_x=split //, $cur_num;
for ($x=$#digits_x; $x >= 0; $x--) {
push (@digits, $digits_x[$x]);
}
unless ($ord > $#digits) {
open IN, "<$PIX_DIR"."$digits[$ord].gif";
} else {
open IN, "<$PIX_DIR"."blank.gif";
}
$blah=;
close IN;
unless ($ord) {
&set_listing;
}
print "Content type: image/gif\n\n";
print $blah;