#!/usr/bin/perl

#written by Andrew Stringer 28/01/03 onwards
#web page counter script

MAIN:
#start of body of program
{
#set up environment variables
$remotehost=$ENV{'REMOTE_ADDR'} ;
$useragent=$ENV{'HTTP_USER_AGENT'} ;


#get system date
$date = localtime;

#print "about to open.counter.txt \n" ;
open COUNTER, "<counter.txt" or die "Cannot open file counter.txt for
input." ;

#read in all of counter.txt in to scalar "$counter"
$input = <COUNTER> ;
#close counter.txt
close COUNTER ;

#create array from scalar $input
@input = split /,/, $input ;

#print "Size of array is $#input \n";
$counter = @input[0] ;
$inputip = @input[1] ;

#set up dummy remotehost
#$remotehost = "10.10.10.10" ;

#increment counter by 1 if remote address is not the same as previous
if ($remotehost ne $inputip) {
        $counter = $counter+1 ;
        #print "$counter" ;
        }

#print "Contents of counter are $counter \n" ;
#print "Contents of ipaddress are $inputip \n" ;
@counter = split //, $counter ;
#print "\n" ;


print "Content-type: text/html\n\n";
#print "$remotehost, $inputip  \n";
print "<table border=\"0\"><tr><td>Visitor Number:-</td> \n" ;
if ( @counter[0] ne "" ) {
print "<td><img src=\"/numerals/@counter[0].png\"
alt=\"@counter[0]\"></td> \n" ;
};

if ( @counter[1] ne "" ) {
print "<td><img src=\"/numerals/@counter[1].png\"
alt=\"@counter[1]\"></td> \n" ;
};

if ( @counter[2] ne "" ) {
print "<td><img src=\"/numerals/@counter[2].png\"
alt=\"@counter[2]\"></td> \n" ;
};

if ( @counter[3] ne "" ) {
print "<td><img src=\"/numerals/@counter[3].png\"
alt=\"@counter[3]\"></td> \n" ;
};

if ( @counter[4] ne "" ) {
print "<td><img src=\"/numerals/@counter[4].png\"
alt=\"@counter[4]\"></td> \n" ;
};

if ( @counter[5] ne "" ) {
print "<td><img src=\"/numerals/@counter[5].png\"
alt=\"@counter[5]\"></td> \n" ;
};

print "</tr></table> \n" ;


#create $output to write back to counter.txt file
$output = join ',', $counter, $remotehost ;
#print "$output \n" ;

#write to file
open COUNTER, ">counter.txt" or die "Cannot open file counter.txt for
output." ;
print COUNTER "$output" ;
close COUNTER ;

}
exit (0);

