Do all header("Location: member.php?id=$username") have to be the first thing in a script? (PHP)
Posted
by ggfan
on Stack Overflow
See other posts from Stack Overflow
or by ggfan
Published on 2010-04-17T02:57:15Z
Indexed on
2010/04/17
3:03 UTC
Read the original article
Hit count: 279
php
I know in the Manuel it says that the header has to be the first thing in a script, but how come I see some codes where header("Location: member.php?id=$username") is in a if-statement?
Ex:
//a bunch of codes above
if($result!="0"){
// authenication correct lets login
$_SESSION["password"] = $password;;
$_SESSION["username"] = $username;
header("Location: member.php?id=$username");
}
else
{
echo "Wrong username or password. Please try again!";
}
But when I do this, it sometimes would/won't throw an error. How do I allow the header (); to be used in a script without any errors? I want to redirect the user back to the login if they click "no" and to the homepage if they click "yes".
© Stack Overflow or respective owner