I want to put an if-statement at the top of a PHP web-page, to confirm that the user has arrived there after using a valid password. The code I've tried is this:
Code:
<?php
if ($_POST["psswd"] == "password") {
search_db();
exit;
} else {
header("Location: http://www.junk.com");
exit;
}
?>
Now, I know, beyond question, that the 'psswd' value is passed from the previous page, because when I replace the code with this:
Code:
<?php
echo $_POST["psswd"] . "<br /><br />";
?>
the correct password shows up in the browser window.
In both cases, this code is the very first thing in the document. There are no blank spaces nor blank lines above or before it. However, the first bit of code consistently fails in that it invariably goes to the 'else' portion of the if-statement and displays the junk.com web-page. It does not run the search_db() function (which I've tested and found reliable).
I've also tried doing this by using a not-equal comparison in the if-statement (using both <> and !=), calling the header in that case, and not using an else-statement to call the search_db() function in that section of code at all, but calling it farther down in the script.
How can I revise my code to get the if-statement to work?