...

View Full Version : using the array_unique function



eon201
11-12-2007, 10:57 AM
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

$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)
{//strip out all this stuff we dont want
$weberror = substr($value, -18, 3); //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);

?>

eon201
11-12-2007, 03:23 PM
ahhh... I have solved my problem. But thanks anyway!:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum