Hi,
I am writing a script to analyse my access log file. And I'm stuck on one area.
I have read a line in, exploded it to retrieve the page that was visited, and now need to increment the relevant counter related to that page.
This is what I have so far:
// Establish the variables
$file = "access.log";
$handle = fopen($file,"r");
$page;
$counter = 0;
$pageArray = array();
$homePage = 0;
$welcomeCounter = 0;
$searchCounter = 0;
while(! feof($handle))
{
// Now do the processing on each line returned
$line = fgets($handle, 1024);
$text = explode(" ",$line);
$page = $text[10];
// Strip the exact page from the variable $page
$exactPage = explode("=",$page);
$visitedPage = $exactPage[1];
// Remove the last character of the string
$visitedPage2 = explode("&",$visitedPage);
$visitedPage = $visitedPage2[0];
// Count the number of visitors by getting the page name, appending 'Page' to the end of it and incrementing the respective counter o_0
$visitedPageCounter = $visitedPage . "Page";
$visitorPageCounter;
//$visitedPageCounter++;
$counter++;
}
It is the last few lines that I am stuck on. The value of $visitedPage for example, is 'welcome' (without the quotes) and then I have added 'Page' to the end of it to get 'welcomePage' as the value of $visitedPageCounter.
Now I want to get the value of $visitedPageCounter and increment it. I don't fancy writing long IF and ELSEIF statements to compare the value of it, so is there a way I can retrieve the value of $visitedPageCounter and to have the code '$welcomePage++' ?
Thanks,
Nathan