I have a strange problem. At the top of my page is an if statement, which seems to be ignored when the header (location: xxx) command is inside it.
$check = $authorisation->check(); // i know this results in true by echoing the value // (you've got to believe me on this one) if(!$check){ // redirect to message header("Location: message.php"); exit; }else{ // do nothing, continue with page }
This is ALWAYS redirected to the message.php page, regardless of the result of $ authorization-> check ()!
Strange, when I comment out the header command and add echo to the if-statement for verification, everything works as expected:
$check = $authorisation->check(); // true if(!$check){ // redirect to message echo "you are not welcome here"; }else{ echo "you may enter"; }
Result: "you can enter";
This also works as expected:
$check = true; if(!$check){ // redirect to message header("Location: message.php"); exit; }else{ // do nothing }
This only redirects to the message page when $ check = false;
The funny thing is that I only have a problem on one server, the same script works flawlessly on testerver.
Any help would be greatly appreciated!
redirect php header if-statement
Olivier
source share