CGI hit counter sobroutine open source

http://blackjackstory.com/cgihit.html     English    中文

I have post HTML hit2.cgi on htt://blackjackstory.com
This is the subroutine on my cgi programs
The $ENV{"SCRIP_NAME"} defined your script as "/cgi-bin/yourcgi.cgi"
drop the first 9 byte $_ will be yourcgi.cgi
replace the cgi with txt your file counter will be change to yourcgi.txt
If this file did not exist, subroutine create one start count 1,
else add 1 to this file and close this file for next hit.
You will only need call this soubroutine one's
 as :   
&pagecnt;

sub pagecnt
{
  $_ = substr($ENV{'SCRIPT_NAME'}, 9, 11);
  $cgi = $_;
  $_ =~ s /cgi/txt/;
   # Set the file name up.
    
$HcntFile =  $_;
# 
# 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 "

$cgi $HitCounts \n"; # print "$HcntFile : $HitCounts \n"; }

Hit 395