Header() function problems
Posted: Thu Dec 02, 2010 4:50 am
I'm writing a script for registering new users, and when the form is submitted it goes to my form handler php script, if there is an error, the php script should redirect the user back the registration form with a message about the error. I'd like to use the header() function to do the redirection, but the code is acting in a way that i can't understand. When header() is called in an if statement that is true, it skips the header() function in the if statement and executes the one outside of the if statement. At first I thought my code was funky, but i broke it down to the simplest example:
This goes to success everytime, even though $error equals 1... I couldn't find a solution or explanation anywhere.
also,
that code will go to 3.php. I'm stumped. If I can't redirect with php in this manner then how should i redirect my pages? I like the header() function because when you use the back button on the browser is skips the script and goes back to the last loaded html page.
Code: Select all
$error = '1';
if($error == '1')
{
header('Location: reg.php');
}
header('Location: success.php');
also,
Code: Select all
$error = '1';
if($error == '1')
{
header('Location: 1.php');
}
if($error == '1')
{
header('Location: 2.php');
}
if($error == '1')
{
header('Location: 3.php');
}