something is going very wrong...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

something is going very wrong...

Post 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
Post Reply