[SOLVED] array woes

This is a discussion on "[SOLVED] array woes" within the PHP Forum section. This forum, and the thread "[SOLVED] array woes are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 6th, 2007, 14:17
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] array woes

Ok so here is my code:
Code: Select all
// calculate all page requests
                $all_request = count($log_request); // calculate all page counts
                
                //calculate dirty page counts(eg gif,jpg,txt,swf,etc)
                $bad_request = substr($bits[5], -3, 3);
                
                // calculate overall page count
                // $good_request = $all_request - $bad_request;
                
                // echo "$good_request";
So what I am trying to do is build a simple url visited counter. i know you canget free ones, but there you go! At the minute its calculating the whole number of values within the array. But when I try to use the substr function to try and work out how many of the values end in jpg, or swf etc I cant egt it to work! Can anyone help??
Reply With Quote

  #2 (permalink)  
Old Nov 6th, 2007, 15:13
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: array woes

That was quite a confusing post in hindsight so I will explain better...

Here is the full code.
PHP: Select all

<?php
// Work out our time and when we search to
$timenow strtotime("now");
$endtime strtotime("-1 hour");

echo 
$timenow "<br />";
echo 
$endtime "<br />";
echo 
"====================+" "<br />";

$filename 'logs/''ex'date('ymd'). '.log'// Filename Checker
    
    
if (file_exists($filename)) // Does the corresponding filename exist - if yes then
    
{
        
$fp fopen($filename"r"); //Open the server log
        
$content fread($fpfilesize($filename));     // Read the server log
        
        
$content explode("\n"$content);
        
        
// $content is the array
        // $dave is a name of a variable to store the key in
        // $value is a name of a variable to store the value in
        
foreach($content as $dave=>$value)    {
            
$firstcharacter substr($value01);
            if(
$firstcharacter == "#" || $firstcharacter == "")    {
            }
            else    {
                
$bits explode(" "$value);
                
                
// CLIENT IP
                // $bits[9]
                
$log_clientIP[] = $bits[9];
                
                
// CLIENT REQUEST
                // $bits[5]
                
$log_request[] = $bits[5];
                
            }
        }
    
        
fclose($fp);

                
// Counts unique values for ip's
                
echo '<br/><br/>';
                
$tlog_clientIP count(array_unique($log_clientIP)) . "<br /><br/>";
                echo 
"Unique Visitors = $tlog_clientIP";
                
                
// Counts page requests
                
echo '<br/><br/>';
                
                
// calculate all page requests
                
$all_request count($log_request); // calculate all page counts value
                
                //calculate dirty page counts
                
$lastthree substr($bits[5], -33);
                if(
$lastthree == "gif|| $lastthree == "jpg" || $lastthree == "txt" || $lastthree == "swf|| $lastthree == "png|| $lastthree == "css|| $lastthree == "/^.js/" || $lastthree == "ico"){
                
                 
//add all of these together to get the value of $bad_request
                
}
                else {
                }
                
            
                
// calculate actual page count value
                //$good_request = $all_request - $bad_request;
                
                //echo "$good_request";
                
                // Calculate avg ppv
                
echo '<br/><br/>';
                
$overallpages count($log_request);
                
$tavgppv $overallpages/$tlog_clientIP;// This needs to be changed to $good_requests
                
echo "Avg PPV = $tavgppv";
                
                
// Calculate top 5 page requests
                
echo '<br/><br/>';
                
print_r(array_count_values($log_request));                
    }
    
    
    
    else 
// Does the corresponding filename exist - if no then
    
{
        echo 
'error!! this file does not exist';
    }
?>
I am pulling in a server log file and creating it into an array. The part I am having trouble with is calculating the actual page view count (as the server not only logs .php,.html files but also, gif, jpeg,txt,swf etc), by working out the overall count $overallpages and then working out the overall count for the file types that i wish to not be included (the dirty page count') and taking the latter away from the first. The only problem is. I have no idea how to do this!

I hope that is a better explanation.

Thanks. eon201

Last edited by c010depunkk; Nov 6th, 2007 at 15:36. Reason: [code] became [php]
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Wireless Network Woes... Jack Franklin Webforumz Cafe 4 Jan 3rd, 2008 18:14
[SOLVED] Fetch Array problem Aso PHP Forum 3 Dec 4th, 2007 16:13
[SOLVED] Array code help longstand PHP Forum 3 Dec 1st, 2007 15:14
[SOLVED] Array sorting welshstew Classic ASP 6 Nov 28th, 2007 16:45
[SOLVED] saving data from one array into another eon201 PHP Forum 2 Nov 7th, 2007 09:34


All times are GMT. The time now is 20:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43