Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry problems with strtotime function

    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 Code:

        <?php

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

                
    $fp fopen($filename"r"); //Open the server log
                
    $content fread($fpfilesize($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

  • #2
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    could it be because the array isn't updating properly?
    PHP Code:
    while ($key >= )
    {
    $log_time $log_time[ ($key 1) ];
    $key--;


  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •