Hit Counter on HTML
Hit counter is just a simple perl program and
Place a html ID as a argument, and generate counter text file on yourhtmlID.
I do not know why the internet make it as a big deal
and tried to make money form it ?
My source code :
1. hit2.pl on your cgi-bin
2. <p>Hit <!--#exec cmd="/home/yourwebID/cgi-bin/hit2.pl yourhtmlID"-->
Where yourhtmlID define as ARGV[0] on hit2.pl
your can change <p> to <tb> or any place on your web HTML code
source code as :
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
# hit2.pl
# blackjackstory.com
# This program counts hits, to a web page.
# It does not count visitors.
# The file name used to count hits is generated using
# the environment variable DOCUMENT_NAME provided by SSI.
# This feature allows this script to be run from any page,
# but still keep counts for each page they are run from.
# The name of each file that you are tracking hits on must be differen
# for this to work correctly.
# Of course you'll need a line like:
# <!--#exec cgi="/cgi-bin/hit2.pl,yourhtmlID"-->
# where yourhtmlID define as argumemt on your html name,
# to implement your SSI and your server must support SSI to
# implement the counter in this manner.
#
# Set the file name up.
if ( !$ARGV[0] )
{
$HcntFile = "./cnt.txt";
}
else
{
$HcntFile = "./$ARGV[0].txt";
}
# Open and read the file.
# $HitCounts is set to 0 if the file doesn't exist.
open (COUNTHAND, "<$HcntFile");
$HitCounts = ;
# Close the file input and open it to truncate output
# Should we worry about locking the file in case another process
# uses it? Probably not since if we take that many hits
# missing a few won't matter and we're too busy to be concerned.
close (COUNTHAND);
open (COUNTHAND, ">$HcntFile");
# Increment $Counter, then write it back out. Put up a message
# with the new value. Close the file and exit.
$HitCounts += 1;
print COUNTHAND $HitCounts;
# flock (COUNTHAND, 8);
close (COUNTHAND);
# print "Content-type: text/plain";
print "$HitCounts";
# End access.pl
Click here Demo Web Hit Counter on HTML
or
Hit 372