#!/usr/bin/perl ################################################################################## # URL Tracker # Copyright 1996 Techno Trade http://www.technotrade.com # Written By : Sammy Afifi sammy@technotrade.com ################################################################################## # Date Last Modified : May 31, 1996 $filename = "hits.txt"; $filecount = "counts.txt"; $shortdate = `date +"%D %T %Z"`; chop($shortdate); $url = $ENV{'QUERY_STRING'}; &open_file("OUTFILE",">>",$filename); &write_file("OUTFILE",$ENV{'REMOTE_HOST'} . " [ " . $shortdate . " ] " . " - " . $url . "\n"); close(OUTFILE); &read_counts; #read in the file that contains URL, count &update_counts; &write_counts; print "Location: $url\n\n"; exit; ################################################ # find URL and increment it's counter else add it to the array ################################################ sub update_counts{ $found = 0; for ($x=1;$x <= $numurls;$x++) { if ($urls[$x] =~ $url) { $counts[$x]++; #increment the # of hits $found = 1; } } if ($found == 0) { #if URL was'nt found then add to the array $numurls++; $urls[$numurls] = $url; $counts[$numurls] = 1; } } ############################################ # Read the counts from the file ############################################ sub read_counts { $numurls = 0; &open_file("FILE1","",$filecount); while ($line = &read_file("FILE1")) { $numurls++; ($urls[$numurls], $counts[$numurls]) = split(/\s*\,\s*/,$line ,2); #split the line at the comma chop($counts[$numurls]); } close(FILE1); } ############################################ #update the counts file ############################################ sub write_counts { &open_file("FILE1",">",$filecount); for ($x=1;$x <= $numurls;$x++) { &write_file("FILE1",$urls[$x] . "," . $counts[$x] . "\n"); } close(FILE1); } sub open_file { local ($filevar, $filemode, $filename) = @_; open ($filevar,$filemode . $filename) || die ("Can't open $filename"); } sub read_file { local ($filevar) = @_; <$filevar>; } sub write_file { local ($filevar, $line) = @_; print $filevar ($line); }