using the array_unique function

This is a discussion on "using the array_unique function" within the PHP Forum section. This forum, and the thread "using the array_unique function 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 12th, 2007, 09:55
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy using the array_unique function

Hi Im trying to work out unique page visits within my script from my server log files. So far I can calculate the page views, but not the UNIQUE page views.

I belive I need to use the array_unique function, but I can't get it to work.

Can anyone help me??

Here is my code:
PHP: Select all

<?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)
        {
//strip out all this stuff we dont want
            
$weberror substr($value, -183); //strip lines beginning with 400/401/403/404/503
            
            
$findme   'Googlebot';
            
$googlebot strpos($value$findme);
            
            
$findme1   'picsearch.com/bot';
            
$picsearch strpos($value$findme1);

            
$findme5   '.gif';
            
$gif strpos($value$findme5);

            
$findme6   '.jpg';
            
$jpg strpos($value$findme6);

            
$findme7   '.txt';
            
$txt strpos($value$findme7);

            
$findme8   '.swf';
            
$swf strpos($value$findme8);

            
$findme9   '.dll';
            
$dll strpos($value$findme9);

            
$findme10   '.asp';
            
$asp strpos($value$findme10);

            
$findme11   '.png';
            
$png strpos($value$findme11);

            
$findme12   '.css';
            
$css strpos($value$findme12);

            
$findme13   '.ico';
            
$ico strpos($value$findme13);
            
            
$findme14   '.js';
            
$js strpos($value$findme14);

            
$findme16   'msnbot';
            
$msnbot strpos($value$findme16);

            
$findme17   'gigablast.com/spider.html';
            
$gigaspider strpos($value$findme17);

            
$findme18   'InternetSeer.com';
            
$internetSeer strpos($value$findme18);

            
$findme19   '+Slurp';
            
$yahoo strpos($value$findme19);

            
$findme20   '....../1.0+';
            
$msnsneakbot strpos($value$findme20);
            
            
            
                if (
$weberror != "400" && $weberror != "401" && $weberror != "403" && $weberror != "404" && $weberror != "503" && $googlebot === false && $picsearch === false && $msnbot === false && $gigaspider === false && $internetSeer === false && $yahoo === false && $msnsneakbot === false && $gif === false && $jpg === false && $txt === false && $swf === false && $dll === false && $asp === false && $png === false && $css === false && $ico === false && $js === false)
                {

                            
//now we have stripped explode
                            
                        
$bits explode(" "$value);
                        @
$request $bits[5];
                        @
$log_client $bits[9];
                        
                        
$log_clientvar explode("\n"$log_client);                        
                        
$result array_unique($log_clientvar);
                        
                
//search for string to find page views for this page
                        
$find 'booked/excursions/';
                        
                        if (
strpos($request$find) == true )
                        {
                        
print_r("$request<br/>");
                        
$n++;
                        }
                        
//Surely I should work out unique page views here???

                
}
                
                else
                {
                }

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

?>
Reply With Quote

  #2 (permalink)  
Old Nov 12th, 2007, 13:54
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using the array_unique function

This code doesn't make a whole lot of sense to me...

You are analysing a web log right? You explode it at the beginning of the file and explode it at each new line '\n'....

This part of the code

$log_clientvar = explode("\n", $log_client);
$result = array_unique($log_clientvar);

What exactly is being exploded on here because all of the new lines are gone from the initial explosion? You are in the middle of a foreach loop here and working with one line at a time.....

$log_clientvar is being reset each time as is result, the array isn't being added to...
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
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
DateTime Function tanya_1985_am Classic ASP 5 Oct 12th, 2007 16:42
Mail function alexgeek PHP Forum 4 Sep 22nd, 2007 12:18
Getting value from function melvinoyh JavaScript Forum 2 May 27th, 2006 00:57
onclick function tomd1985 JavaScript Forum 0 Mar 13th, 2006 18:20
SQL Function spinal007 Databases 1 Mar 25th, 2005 09:43


All times are GMT. The time now is 11:42.


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