#!/usr/local/bin/perl ############################ ## Simple Counter 2.5 ## ## By Linden Bronleigh ## ## linden@iinet.net.au ## ############################ ################################### # See readme.rtf for Instructions # ################################### #### VARIABLES #### #Path To Image Files (Include The Slash at the end or leave blank if the images are in the same directory as the script file) my $imgpath="digits/"; #Extension of image files (Include the dot) my $ext=".gif"; #Width of image my $width="15"; #Height of image my $height="20"; #Server on which counter is going to be used: my $server="www.wildboar.net"; #Use Server Protection (0=no, 1=yes) my $useserver=1; ################### #################################### # DO NOT EDIT BELOW THIS POINT # #################################### $start=1; print "content-type: text/html\n\n"; if ($ENV{'QUERY_STRING'} ne "" and $ENV{'QUERY_STRING'} ne "stats") { if ($useserver) { if ($server ne $ENV{'HTTP_HOST'}) { print "This Counter has been setup to only work on $server, not $ENV{'HTTP_HOST'}\n\n"; $start=0; } } if ($start==1) { &doform; $ip=$ENV{'REMOTE_ADDR'}; open (IP, "counter.cnt"); $line=; close (IP); @files=split(/\|/,$line); foreach $file (@files) { ($file,$count,$lastip)=split(/:/, $file); if ($file eq $form{'file'}) { $thecount=$count+1 if ($ip ne $lastip); $thecount=$count if ($ip eq $lastip); } else { $untouched.="|$file:$count:$lastip"; } } $thecount=1 if ($thecount==0); if ($form{'type'} eq "text") { open (COUNT, ">counter.cnt"); print COUNT "$form{'file'}:$thecount:$ip$untouched\n"; close (COUNT); print "$thecount"; } else { @nums = split(//, $thecount); foreach $num (@nums) { $printcount = "\"$num\""; print $printcount; } open (COUNT, ">counter.cnt"); print COUNT "$form{'file'}:$thecount:$ip$untouched\n"; close (COUNT); } ###FORM PROCESS sub doform { $it=$ENV{'QUERY_STRING'}; @blah=split(/&/,$it); foreach $i (@blah) { ($id,$val)=split (/=/,$i); $form{$id}=$val } } ####### } #END } elsif ($ENV{'QUERY_STRING'} eq "stats") { open (IP, "counter.cnt"); $line=; close (IP); @files=split(/\|/,$line); print "\n\nCounter Stats\n\n\n

Counter Stats

\n

\n"; foreach $file (@files) { ($file,$count,$lastip)=split(/:/, $file); print "$file Hits=$count
\n"; } print "

\n \n\n\n"; } elsif ($ENV{'QUERY_STRING'} eq "" and $ENV{'QUERY_STRING'} ne "stats") { print "Please Specfy a file. For example, you would type:\ncounter.cgi?file=thefile.html\n"; }