...

View Full Version : problems with strtotime function



eon201
11-13-2007, 10:59 AM
Im having trouble getting the the correct answer when I take one strored time away from another. Can anyone see why??

Here is the code:



<?php

$filename = 'logs/'. 'ex'. date('ymd'). '.log'; // Filename Checker

$fp = fopen($filename, "r"); //Open the server log
$content = fread($fp, filesize($filename)); // Read the server log
$content = explode("\n", $content); // explode into array
//$content = array_reverse($content ); // reverse the array
$n =0;
$n2 =0;
foreach ($content as $key=>$value)
{


$bits = explode(" ", $value);
@$request = $bits[5]; // Get cs uri stem
@$log_client = $bits[9]; // Get client ip
@$log_time = $bits[1]; // Get client time


$log_time = strtotime($log_time);
$mylogtime = $log_time - $log_time[$key - 1];

$find = 'booked/excursions/index.php';

if (strpos($request, $find) == true)
{
print_r("$request ");
$n++;
echo "$log_time - This is the whole number<br/>";
echo "$mylogtime - This should not be the whole number but the sum.<br/><br/>";

if (($mylogtime) > (420)){
$n2++;
}


}


else
{
}

}
echo "<br/>Page views for '$find' = $n<br/><br/>";
echo "<br/>Unique page views for '$find' = $n2<br/><br/>";
fclose($fp);

?>




Here is the output of the file:

/booked/excursions/index.php 1194941763 - This is the whole number
1194941763 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194953776 - This is the whole number
1194953776 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194954604 - This is the whole number
1194954604 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194954612 - This is the whole number
1194954612 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194955060 - This is the whole number
1194955060 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194956424 - This is the whole number
1194956424 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194957320 - This is the whole number
1194957320 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194957433 - This is the whole number
1194957433 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194957902 - This is the whole number
1194957902 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194958178 - This is the whole number
1194958178 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194958543 - This is the whole number
1194958543 - This should not be the whole number but the sum.

/booked/excursions/index.php 1194959837 - This is the whole number
1194959837 - This should not be the whole number but the sum.


Warning: strtotime() [function.strtotime]: Called with an empty time parameter. in D:\home\Default\planetcruise-svr.co.uk\htdocs\pcm\logreader4.php on line 37

Page views for 'booked/excursions/index.php' = 12


Unique page views for 'booked/excursions/index.php' = 12


I just cant see why the stored numbers dont do the sum. Can anyone else??

Thanks in advance. EOn201

psykx
11-13-2007, 12:00 PM
could it be because the array isn't updating properly?


while ($key >= 0 )
{
$log_time = $log_time[ ($key - 1) ];
$key--;
}

eon201
11-13-2007, 12:29 PM
hmm.. not sure,

But all I need it to do is to read the current timestamp within the loop, and subtract the previous time stamp from it. Once it has done this it needs to work out if the sum is less than 420, if so then $n2++.

I hope this makes more sense



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum