<?php
####
#
# Counts the number of times self is accessed in
# /private/var/log/httpd/access_log
#
#
# Written by: Michael Sanford
# It's a counter, copy at will!
#
####
// Set the count to zero.
$count = 0;
// Open the Apache log file (default installation location).
$accessLogHandle = fopen("/private/var/log/httpd/access_log", "r");
// Go through the file looking for the calling script's name.
while (!feof($accessLogHandle)) {
$haystack = fgets($accessLogHandle, 4096);
$position = strpos($haystack, $_SERVER['PHP_SELF']);
if ($position) $count++;
// Diagnostic output
// echo $haystack . "\t<b>" . $count . "</b><br>";
}
// Close the apache log file.
fclose($accessLogHandle);
// Print the information
echo "<b>" . $_SERVER['PHP_SELF'] . "</b> has been accessed <b>" . $count . "</b> times.";
?>