I have a site with a form. When the form submits, the page is processed, and then depending on the outcome of the code, sets a session variable and then redirects to the page. That way the user never has a refresh situation where the browser alerts them about it needing to resubmit POST data.
So basically this:
if ( $mail->Send( ) )
{
$_SESSION['ERROR'] = "Your email was sent successfully.";
header( "location: contact.php" );
}
else
{
$_SESSION['ERROR'] = "An error has occurred sending your email. Please try again later.";
header( "location: contact.php" );
}
Pretty straight forward.
Anyway, I need to make sure that error variable gets cleared for later use. So at the point where I echo it out to the user, I then just set it to "". Like so:
<?PHP
//This is for any errors that occur, they can be announced here
if ( ( $_SESSION['ERROR'] != "" ) or ( $_SESSION['ERROR'] != null ) )
{
$error_msg = $_SESSION['ERROR'];
$_SESSION['ERROR'] = "";
echo "<p>";
echo "- ".$error_msg."<br />\n";
echo "</p>";
}
?>
I don't get it, but any time, anywhere on the page that I try to clear the ERROR session variable, it clears it completely. No matter where I put the statement to set it to "" its like it sets it to that globally for the whole page and nothing gets printed at all.
Any ideas?