I'm running an If Else statement which basically loads a different Form each time the page is refreshed. The statement is placed in sidebar.php, and as a result the form shows on every page as it should. For some reason the If Else statement appears to run both the if and else, or is running it twice.
I added the echos to see what was happening, same with append for the fwrite. Basically, what I do here is write a file whichagent.php change the variable every time the page is loaded. The if statement checks the variable and loads the form, then writes the change to the whichagent.php file so the next time the variable is different.
Any ideas anyone?
Here's the code:
<?php
include('../whichagent.php');
echo $whichagent;
if ( $whichagent == 2 ) {
insert_cform('1');
$fh=fopen('../whichagent.php','a');
fwrite($fh, '<?php $whichagent=1; ?>');
fclose($fh);
echo "Pass 1st";
} else {
insert_cform('2');
$fh=fopen('../whichagent.php','a');
fwrite($fh, '<?php $whichagent=2; ?>');
fclose($fh);
echo "Pass 2nd";
}
?>