Page 1 of 1

something is going very wrong...

Posted: Sun Nov 01, 2009 5:13 pm
by Monotoko
Hiya :)
was just wondering if i could have your help with this simple piece of code, maybe im missing something, i dont know..but its been driving me mad

Code: Select all

 
<?php
session_start(); //start session
$sitewrite=$_REQUEST['search']; //get the search variable from the URL
if ($sitewrite != $homepageproduct) //if the variable != homepageproduct, it means they have used the search function
{
if ($_SESSION['searches'] != $sitewrite) //This should ensure the filewrite is only run once
{
echo $sitewrite;
$fh = fopen("../../pubstermax/inc/searches.csv", "a");
fwrite($fh, $sitewrite."\n");
fclose($fh);
$_SESSION['searches'] = $sitewrite; //now...if it runs through this again, it should skip the file writing
}
}
?> 
It is linked to some other files, i will tell you where the other varaibles come from:
basically the $homepageproduct check, checks if something has been searched, if it has, it tries to log it.

My problem is, it is writing to the file 3 times with the same thing, so i thought it was maybe loading the page a few times, so added the session
but that didnt do anything either

i have echoed the variable it is writing as you can see, it only echo's once, i have checked the session, which does = the variable sitewrite

So now im confused, why is it writing 3 times?!

~Monotoko