[PHP] log analysis

2002-05-10 Thread Josh Edwards

Hi there,

I'm working on using php to analyse an access log on an apache server.

If a user inputs a file path I  want to be able to use PHP to determine if
it's a log file. Is there a function that will reject if it's not a binary
file. If it's a binary file how would I then
compare it  to whats expected in a log file.

Any help is appreciated

J




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] log analysis

2002-05-10 Thread Josh Edwards

Thanks for replying  Miguel

I'm new to php and wonder how I would check if the first field  is an IP
address. Do I  open the file fget it and then use a regular expression to
check. Also if I want to break up the first line of my array what delimiter
do I look at as  the fields in the log are seperated by spaces.

J

"Miguel Cruz" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Fri, 10 May 2002, Josh Edwards wrote:
> > I'm working on using php to analyse an access log on an apache server.
> >
> > If a user inputs a file path I  want to be able to use PHP to determine
if
> > it's a log file. Is there a function that will reject if it's not a
binary
> > file. If it's a binary file how would I then
> > compare it  to whats expected in a log file.
>
> 1. Apache logs are text files.
>
> 2. The difference between a binary file and a text file is not something
> that can be observed, only declared. Well, it can be observed by humans,
> but not by machines. Who knows how picky a given application is going to
> be about line endings? Who knows what text encodings are valid in the
> context?
>
> 3. The format for Apache log files depends on the configuration of the
> server (directives like LogFormat).
>
> 4. If you know the configuration of the server, then it's trivial to
> determine whether you have a valid log file. If the first column is
> supposd to be an IP address, check for an IP address. If the fourth column
> is supposed to be a date, check for a date.
>
> miguel
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Where's the error?

2002-05-13 Thread Josh Edwards

This is meant  to grab a date out of a log file from the first line of the
array but I'm getting a parse error on line 13. Any  ideas?

function getdate($hit)
 {
$single = explode (" ",$hit);
return $single[3].$single[4];
}

$filename = ("combined_log");

fopen ($filename, "r");

$fcontents = file($filename);
 $limit = 1;
for ($i = 0; $i <= $limit; $i++)
{
$line = $fcontents[i];
if ($line! = " ")
{
$currentdate = getdate($line);
echo $currentdate;
}
}




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Where's the error?

2002-05-13 Thread Josh Edwards

Thanks heaps for your help I really appreciate it.  I have made the changes
you suggested but now I only get a blank screen.

function getmydate($hit)
 {
$single = explode (" ",$hit);
return $single[3].$single[4];
}

$filename = ("combined_log");

//fopen ($filename, "r");

$fcontents = file($filename);
 $limit = 1;
for ($i = 0; $i <= $limit; $i++)
{
$line = $fcontents[i];
if (!empty($line))
{
$currentdate = getmydate($line);
echo $currentdate;
}
}





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Where's the error?

2002-05-13 Thread Josh Edwards

I put 'print_r($fcontents);'  in and it outputted the array of my log file
so I'm not sure what's wrong.

Here's a section of the log file. I'm trying to get the date of the first
access and the last access.

203.29.154.13 - - [08/May/2002:21:21:22 +1000] "GET /A1.html HTTP/1.1" 304 -
"-"
 "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [09/May/2002:21:21:23 +1000] "GET /A1.html HTTP/1.1" 304 -
"-"
 "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [10/May/2002:21:21:24 +1000] "GET /A1.html HTTP/1.1" 304 -
"-"
 "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"

Regards

Josh

"Lars Torben Wilson" <[EMAIL PROTECTED]> wrote in message
1021345553.886.133.camel@ali">news:1021345553.886.133.camel@ali...
> On Mon, 2002-05-13 at 20:01, Josh Edwards wrote:
> > Thanks heaps for your help I really appreciate it.  I have made the
changes
> > you suggested but now I only get a blank screen.
> >
> > function getmydate($hit)
> >  {
> > $single = explode (" ",$hit);
> > return $single[3].$single[4];
> > }
> >
> > $filename = ("combined_log");
> >
> > //fopen ($filename, "r");
> >
> > $fcontents = file($filename);
> >  $limit = 1;
> > for ($i = 0; $i <= $limit; $i++)
> > {
> > $line = $fcontents[i];
> > if (!empty($line))
> > {
> > $currentdate = getmydate($line);
> > echo $currentdate;
> > }
> > }
>
> Things to check:
>
>  o Put 'error_reporting(E_ALL);' as the first line of your script.
>  o Are you sure it's reading the file? Try 'print_r($fcontents);' after
>the file() call.
>
> That might get you a little farther. Otherwise post a few
> representative lines from combined_log; otherwise we won't
> have any real data to work with.
>
>
> --
>  Torben Wilson <[EMAIL PROTECTED]>
>  http://www.thebuttlesschaps.com
>  http://www.hybrid17.com
>  http://www.inflatableeye.com
>  +1.604.709.0506
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Where's the error?

2002-05-13 Thread Josh Edwards

Fixed !!!
It should  be $line = $fcontents[$i];
not $line = $fcontents[i];

Would you know the syntax to get the the last date? ie
$lastdate = getmydate($line[(count($line))]);
echo "$lastdate";




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Newbie challenge to brainiacs

2002-05-14 Thread Josh Edwards

I'm a PHP  beginner and  I  am amazed at the  help people give you in this
newsgroup. I'm trying to  attempt something  ambitious (for me anyway) and
I'm looking for help.


Here is a sample of my weblog that reads into an array from a file ie

$filename = ("combined_log");
$fcontents = file($filename);

203.29.154.13 - - [08/May/2002:21:21:07 +1000] "GET /A1.php HTTP/1.1" 200
417 "-
" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [08/May/2002:21:21:10 +1000] "GET /A1.php HTTP/1.1" 200
417 "-
" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [10/May/2002:20:10:11 +1000] "GET /A1.php HTTP/1.1" 200
417 "-
" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [11/May/2002:19:15:12 +1000] "GET /A1.php HTTP/1.1" 200
417 "-
" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
203.29.154.13 - - [12/May/2002:15:21:13 +1000] "GET /A1.php HTTP/1.1" 200
417 "-
" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"

I want to try to find the hour that has the most hits
The day of the week that has the most hits
and the max and ave  no of hits of these.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Newbie challenge to brainiacs

2002-05-15 Thread Josh Edwards

The challenge is to do it without SQL. Which blog do you recommend?


"David Jackson" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Jay Blanchard wrote:
> >
> The burning issue that begs to be answered is, why reinvent the wheel?
> There is a least a dozen blogs on freshmeat for PHP along...
> Unless your doing it just for kicks, which is OK.
>
> David
>
>
> > [snip]
> >  > I want to try to find the hour that has the most hits
> >  > The day of the week that has the most hits
> >  > and the max and ave  no of hits of these.
> >
> > I haven't given it a whole lot of thought but I'd be tempted to dump the
> > whole thing into an appropriately structured sql database and then use
> > SELECT's to extract the information you want.  It'll likely end up
> > faster and less processor intensive than doing it in php by itself I
> > suspect.
> > [/snip]
> >
> > +1
> >
> > Not only that, but then you will have the ability to create queries for
> > other important factors in the logs without having to recode, or create
> > code.
> >
> > Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Newbie - Spot the error

2002-05-15 Thread Josh Edwards

if I have $time = 21  then

$timespread =array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
 if ($time = = "21")
 $timespread[22]=($timespread[22]+1);
 echo $timespread[22] ;

I get 0




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Newbie - Spot the error

2002-05-15 Thread Josh Edwards

If I // $time=="21" the count goes up by 1 so it's not recognizing the 21.

Any ideas


"Olav bringedal" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> --- Josh Edwards <[EMAIL PROTECTED]> wrote: > if I
> have $time = 21  then
> >
> > $timespread
> >
> =array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
> >  if ($time = = "21")
> >  $timespread[22]=($timespread[22]+1);
> >  echo $timespread[22] ;
> >
> > I get 0
> >
>
> It might be "= =" which should be "==". If not, try:
>
>  $timespread =array
> (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
>   if ($time == "21")
> {
> echo "before:".$timespread[22]."" ;
> $timespread[22]=($timespread[22]+1);
> echo "after:".$timespread[22]."" ;
> }
> else
> {
> echo "time is not 21" ;
> }
>
> Then you can at least establish where things go wrong.
>
>
>
>
> =
> Olav Bringedal
> jaggu.org
>
> __
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] help with arrays

2002-05-16 Thread Josh Edwards

This is a basic question but I'm  a basic fellow. If I have an array

$timespread = array("12am-01am"=>0);
$timespread["01am-02am"]=0;
$timespread["02am-03am"]=0; etc

Using $time which is a number, I want to add 1 to the value of
$timespread[$time] without changing the key so if $time =1
I want to have $timespread["01am-02am"]=1;

Using $timespread[$time]+=1; doesn't work.

any ideas?





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] array question

2002-05-17 Thread Josh Edwards

I have an array which I use a loop to add numbers to different elements in
the array. I can extract the highest no
which in this case is 48. ie ([22 ] => 48 [23 ] => 2 [12 ] => 22 [14 ] =>
5 )

Using this highest no (48 in this instance), how do I get the position or
[element No] that matches the highest no.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Array problems again

2002-05-17 Thread Josh Edwards

Here's a sample of a weblog. I have a loop that extracts the request ie "Get
/A1.php
How do I  get the top ten requests and how many time these were requested
after looping thru the whole file. Can you set up an array that is self
populating if a string doesn't match an element in the array or is there a
better way?

203.29.154.13 - - [08/May/2002:21:21:07 +1000] "GET /A1.php
HTTP/1.1" 200417 "-" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"

Any help is greatly appreciated.

J



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] mktime()

2002-05-17 Thread Josh Edwards

After reading the manual Istill can't convert this
09/May/2002 to a timestamp.

Any Pointers



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] date functions

2002-05-18 Thread Josh Edwards

Does anyone know  a good way to count the days between two dates. ie how
many Mondays fall between two dates. As a starting  point I have calculated
the start and end dates and the no of days b/w them.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Help with file read

2002-05-19 Thread Josh Edwards

Can someone look and help

I have a  function that returns the date in this format
[10/Apr/2002:01:17:27 +1000] but I'm having trouble returning the last date
in the file.

$totalhits = count($fcontents);
$filename = ("combined_log");   //open file

$fcontents = file($filename);   //read into array
 //print_r($fcontents);

$limit = 1;
for ($i = 0; $i < $limit; $i++)  //loop
 {
 $line = $fcontents[$i];
  if (!empty($line))

 {
  $currentdate = getmydate($line);  //call function that returns first date.
This is OK
  $currentdate = substr($currentdate, 1);
  $currentdate= substr_replace($currentdate, " ", -15);
   echo "First day of access " .$currentdate;

  $lastdate = getmydate($fcontents[count($fcontents)-1]);
//**This is returning nothing?
  $lastdate = substr($lastdate, 1);
  $lastdate= substr_replace($lastdate, " ", -15);
   echo "Last day of access " .$lastdate;
 }
 }




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php