Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
BohrMe
Hangin' Around



Joined: May 01, 2004
Posts: 28
Location: Fall River, MA

PostPosted: Wed Feb 09, 2005 10:51 pm Reply with quote

I'm stuck. What I'm trying to do is create a simple log analyzer that reads in an apache log, grab the IP address and time stamp, and then summarize the number of hits per IP per time (or whatever format).

I can grab the information just fine but I'm getting stumped on building the array.

Here's what I have:
Code:
$fp = fopen( $filename, "r" ) or die ("Couldn't open $filename for read!\n");


   while ( ! feof( $fp )) {
      $entry = fgets( $fp );
      preg_match( '/^(.*?)\s.*?\[(.*?)\s/', $entry, $first2 );

Inserting a print_r on $first2 gives this type of ourput:
Code:
Array

(
    [0] => 199.0.204.204 - - [30/Jan/2005:08:26:03
    [1] => 199.0.204.204
    [2] => 30/Jan/2005:08:26:03
)

That is what I want but I need to build an array using first2[1] and [2].

Would someone kindly nudge me in the right direction?

Thanks.

_________________
BohrMe
eSnider.net 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Feb 10, 2005 5:38 am Reply with quote

Not sure I'm tracking here. If $first2 is comprised of $first2[0], [1], and [2], then just have a statement after that like

$newArray[0] = $first2[1];
$newArray[1] = $first2[2];

or, to build an ongoing array that you will later parse by every 2 statements,

$newArray[] = $first2[1];
$newArray[] = $first2[2];

Since that sems way too simple, that's probably not what you want.
 
View user's profile Send private message
BohrMe







PostPosted: Thu Feb 10, 2005 10:50 pm Reply with quote

That will work for now but if I add more elements, such as referrer, browser agent, etc, it could get a little tricky sorting and such.

Maybe I should build the array with all the apache log elements in the array and then only load what I want to see...

Code:
$log = array ( 

               array (
                  'ip'=>"",
                  'date'=>"",
                  ,request_type'=>"",
    ...etc...     )
          )


I wonder how I could dynamically populate this kind of array?
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©