#!/usr/bin/perl
##########################################################################
# Simple Animated Counter 1.1 (Javascript) #
# Author: Chi Kien Uong #
# URL: http://www.proxy2.de #
# #
# 1.Change the url in line one, to the Perl program at your server. #
# Usually it is: /usr/bin/perl or /usr/local/bin/perl . #
# #
# 2.Upload the counter.pl to your cgi-bin directory #
# and change mode it to 755. #
# #
# 3.Set the correct paths below and use #
# #
# in your html document to call the counter. #
# That's all. #
# #
# For more stuff visit http://www.proxy2.de #
##########################################################################
# how many digits to show
$padding = 6;
# path to the log file
$log_dat = "hits.txt";
# url to the digits
$img = "http://www.stat.psu.edu/~yuzhang/counter/";
# url to the animated digits
$animated_img = "http://www.stat.psu.edu/~yuzhang/counter/ani/";
# use file locking; ($lock=0 for Win32)
$lock = 0;
# digit width and height
$width = 16;
$height = 22;
# optional configuration settings
$lock_ip =0; # IP locking (counter doesn't increments when page is reloaded) 1=yes 0=no
$ip_lock_timeout =30; # in minutes
$fpt_ip = "ip.txt"; # path to ip log file
# End Setup
##################
print "Content-Type: text/html\n\n";
sub checkIP {
open (FILE,"$fpt_ip");
@ip_array = ;
close (FILE);
open (TABLE,">$fpt_ip") || &error("Cannot create ip log file.\n");
$this_time = time();
foreach $visitor (@ip_array) {
($ip_addr,$time_stamp) = split(/\|/,$visitor);
if ($this_time < $time_stamp+(60*$ip_lock_timeout)) {
if ($ip_addr eq $ENV{'REMOTE_ADDR'}) {
$found=1;
} else {
print TABLE "$ip_addr|$time_stamp";
}
}
}
print TABLE "$ENV{'REMOTE_ADDR'}|$this_time\n";
close(TABLE);
return ($found==1) ? 1 : 0;
}
sub error {
print "$_[0]";
exit (0);
}
$flag = ($lock_ip==1) ? &checkIP : 0;
if (!(-e "$log_dat")) {
open (FILE,">$log_dat") || &error("Cannot create log file.\n");
$count = 0;
print FILE "$count";
close (FILE);
}else {
open (FILE,"+<$log_dat");
$count = ;
if ($lock_ip==0 || ($lock_ip==1 && $flag!=1)) {
flock(FILE,2) if ($lock == 1);
$count++;
seek(FILE,0,0);
print FILE "$count";
}
close (FILE);
}
$count = sprintf("%0"."$padding"."d", $count);
@digits = split(//, $count);
$count++;
@ani_digits = split(//, $count);
#print "";
exit(0);