1. <?php
  2. // Script: Find Phrase in Logfile
  3. // Author: Stephen Lance
  4. // Homepage: http://stephen.calvarybucyrus.org
  5. // Email: pksml@netscape.net
  6. // Version: 1.0
  7. // Release Date: Monday, July 10, 2006
  8.  
  9. header("Cache-Control: no-cache"); // Browser will always get current results
  10.  
  11. // Get variables from the query string
  12. $file = $_GET['file'];
  13. $phrase = $_GET['phrase'];
  14.  
  15. if ($_GET['file']) {$file = urldecode($_GET['file']);}
  16. if ($_GET['phrase']) {$phrase = urldecode($_GET['phrase']);}
  17.  
  18. // Default File, if none specified in the query string
  19. // This file should be your server's logfile
  20. if (!$_GET['file']) {$file = c:/progra~1/abyssw~1/log/access.log";}
  21. // Default phrase to search for, if not specified in the query string
  22. if (!$_GET['phrase']) {$phrase = "google";}
  23.  
  24. $lines = file($file); // Get logfile into $lines array.
  25. $num = count($lines); // Count number of array entries
  26.  
  27. echo "<PRE>";
  28. print "Logfile: <b>$file</b>\n";
  29. print "Lines: <b>$num</b>\n\n";
  30. print "Phrase: \"<b>$phrase</b>\"\n";
  31. print "Usage: <a href=\"".$_SERVER['PHP_SELF']."?file=/website/log/cbc-access.log&phrase=".date(d)."/".date(M)."/".date(Y)."\">";
  32. print $_SERVER['PHP_SELF']."?file=/website/log/cbc-access.log&phrase=".date(d)."/".date(M)."/".date(Y)."</a>\n\n\n";
  33.  
  34. $number = 0;
  35. foreach ($lines as $line_num => $line)
  36. {
  37. if (preg_match("|$phrase|", $line)) {echo "$line"; $number = $number + 1;}
  38. }
  39. echo "\n<P>Number of occurrences: <B>$number</B></P>";
  40. ?>