#!/usr/bin/perl $link = $ENV{'QUERY_STRING'}; $Counter = "countlul.log"; # Add hit to main counter open (CNT,"+<$Counter") || &endIt; flock (CNT,2); seek (CNT,0,0); @infile = ; # This will put the hits in order from max to min for each file added $record = 0; # Starting record in the log is always 0 $correctspot = 'N'; # Tells script if this record is the one that was hit # Proceeds as long as the record number is less than the total # number of records in the file and the correct record hasn't been found yet. while (($correctspot eq 'N') && ($record <= $#infile)) { ($count,$linkname,$eol) = split(/\|/,$infile[$record]); if ($linkname eq $link) #if this is the right record, hit it, trip correctspot {$count++; $infile[$record] = join ("\|",$count,$linkname,"\n"); $correctspot = 'Y'; } $record++; } if ($correctspot eq 'N') { $count = 1; $newrecord = join ("\|",$count,$link,"\n"); push @infile, $newrecord; } @outfile = sort {($b =~ /(\d+)/)[0] <=> ($a =~ /(\d+)/)[0]} @infile; seek (CNT,0,0); print (CNT @outfile); truncate (CNT,tell(CNT)); close (CNT); print "Content-type: text/html\n"; print "Location: http://$link\n\n"; sub endIt { exit; }