PHP and Abyss logs

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
SillyNoodlz
-


Joined: 18 Oct 2005
Posts: 40
Location: France

PostPosted: Tue Oct 25, 2005 7:58 pm    Post subject: PHP and Abyss logs Reply with quote

Ok, A question ...

How would I go about making a stats page from the abyss log ?

Take for example :

86.000.000.000 - - [25/Oct/2005:20:40:45 +0200] "GET /mysite/page2.htm HTTP/1.1" 200 400 "http://www.mydomain.com/mysite/index.htm" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"


How would I break that down so it could be processed with php?

For example, log_stats.php would enter the following into an sql database :

All IP's, to know which visit the most often.
All pages/files opened or downloaded, to know which are the most popular.
All referrers, to know who referrs the most.
All browsers and operating systems, to know which is the most popular.

The entering of values into sql and processing to make the stats after, I can do myself.

The question is, how do I get the values from the log file into the php script?

For example, someting like this :

$ip="86.000.000.000";
$page="/mysite/page2.htm";
$referer="http://www.mydomain.com/mysite/index.htm";
$system="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"

If that makes sense ? lol ...
_________________
~ Dan
One day, I'll finish this ...
My website : www.sillynoodlz.com
Back to top View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Oct 26, 2005 1:00 pm    Post subject: Re: PHP and Abyss logs Reply with quote

DanzServ wrote:
How would I break that down so it could be processed with php?

You can break the line using the standard PHP string functions or using the regexp functions. Have a look on http://www.cs.cf.ac.uk/Dave/PERL/node241.html to get the idea (although they use Perl, the same concept can be translated to PHP).

Quote:
The question is, how do I get the values from the log file into the php script?

Open the file, and read it line by line... For each line, do the necessary to break it into an IP, date/time, etc...
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Oct 26, 2005 10:31 pm    Post subject: Reply with quote

I created a PHP script based on the tutorial , what they want you to do
is create each variable into an array and use a loop to output the type
of data your looking for. This code can be very useful to some.

Code:

<?php
// Log Analyzer Code

if (file_exists("access.log")) {
 $open = fopen("access.log", "r");

 while (!feof($open)) {
  $line = fgetcsv($open, 1024, " ");
 
  // Create $site array
   $site[] = $line[0];

  // Create $logname array
   $logname[] = $line[1];

  // Create $fullname array
   $fullname[] = $line[2];

  // Create $date array
   $date[] = $line[3];

  // Create $time array
   $time[] = $line[4];

  // Create $gmt array
   $gmt[] = $line[5];

  // Create $req array
   $req[] = $line[5];

  // Create $file array
   $file[] = $line[6];

  // Create $photo array
   $proto[] = $line[7];

  // Create $status array
   $status[] = $line[8];

  // Create $length array
   $length = $line[9];

 } // End of While loop

// Note: You can use a foreach loop to
// extract each array , hope this helps.
// Here's an Example

 foreach($date as $str_date) {
  echo $str_date . "<br>";
 }
}else{
 echo "access.log does not exist , please create it.";
 exit;
}
?>


Note: When your using the foreach() loop , you can do the regular
expression match in order to remove the useless characters. LateR!

Even after a match is found , you can continue these regular
expression matches and remove more char(s) from $date. :-)

Example:

Code:

foreach($date as $str_date) {
 if (ereg("^\[", $str_date)) {
  $str_date =  ereg_replace("^\[", "", $str_date);
 }
 if (ereg("\/+", $str_date)) {
  $str_date =  ereg_replace("\/+", "-", $str_date);
 }
 if (ereg(":", $str_date)) {
  $str_date = explode(":", $str_date);
 }
 $date_format = explode("-", $str_date[0]);
 echo $date_format[1] . " " . $date_format[0]
 . "," . " " . $date_format[2] . "<br>";

 // New: Oct 26, 2005
 // Original: [26/Oct/2005:14:30:54]
}


Sincerely , TRUSTpunk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group