That was quite a confusing post in hindsight so I will explain better...
Here is the full code.
- PHP: Select all
<?php
// Work out our time and when we search to
$timenow = strtotime("now");
$endtime = strtotime("-1 hour");
echo $timenow . "<br />";
echo $endtime . "<br />";
echo "====================+" . "<br />";
$filename = 'logs/'. 'ex'. date('ymd'). '.log'; // Filename Checker
if (file_exists($filename)) // Does the corresponding filename exist - if yes then
{
$fp = fopen($filename, "r"); //Open the server log
$content = fread($fp, filesize($filename)); // Read the server log
$content = explode("\n", $content);
// $content is the array
// $dave is a name of a variable to store the key in
// $value is a name of a variable to store the value in
foreach($content as $dave=>$value) {
$firstcharacter = substr($value, 0, 1);
if($firstcharacter == "#" || $firstcharacter == "") {
}
else {
$bits = explode(" ", $value);
// CLIENT IP
// $bits[9]
$log_clientIP[] = $bits[9];
// CLIENT REQUEST
// $bits[5]
$log_request[] = $bits[5];
}
}
fclose($fp);
// Counts unique values for ip's
echo '<br/><br/>';
$tlog_clientIP = count(array_unique($log_clientIP)) . "<br /><br/>";
echo "Unique Visitors = $tlog_clientIP";
// Counts page requests
echo '<br/><br/>';
// calculate all page requests
$all_request = count($log_request); // calculate all page counts value
//calculate dirty page counts
$lastthree = substr($bits[5], -3, 3);
if($lastthree == "gif" || $lastthree == "jpg" || $lastthree == "txt" || $lastthree == "swf" || $lastthree == "png" || $lastthree == "css" || $lastthree == "/^.js/" || $lastthree == "ico"){
//add all of these together to get the value of $bad_request
}
else {
}
// calculate actual page count value
//$good_request = $all_request - $bad_request;
//echo "$good_request";
// Calculate avg ppv
echo '<br/><br/>';
$overallpages = count($log_request);
$tavgppv = $overallpages/$tlog_clientIP;// This needs to be changed to $good_requests
echo "Avg PPV = $tavgppv";
// Calculate top 5 page requests
echo '<br/><br/>';
print_r(array_count_values($log_request));
}
else // Does the corresponding filename exist - if no then
{
echo 'error!! this file does not exist';
}
?>
I am pulling in a server log file and creating it into an array. The part I am having trouble with is calculating the actual page view count (as the server not only logs .
php,.
html files but also,
gif, jpeg,txt,
swf etc), by working out the overall count $overallpages and then working out the overall count for the file types that i wish to not be included (the dirty page count') and taking the latter away from the first. The only problem is. I have no idea how to do this!
I hope that is a better explanation.
Thanks. eon201