Re: User Redirection if login fails
| From: | Matthew Sims | Date: | Thu, 08 Jul 2004 16:09:17 +0000 |
| Subject: | Re: User Redirection if login fails | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189975@lists.php.net to get a copy of this message | ||
> Hi again.
>
> My code simply asks for a username and password but even if they insert
> incorrect details the called page is displayed.
>
> How can I get them to be redirected to another page if their login
> information is incorrect...?
>
> echo "<p><h2>registerd users login here
> please...</p></h2>";
> echo "<form action = 'members/index.php' method='POST'>";
> echo "<pre>UserID:\t\t<input type = 'text' name =
> 'TXT_UserID'></pre>";
> echo "<br><br>";
> echo "<pre>Password:\t\t<input type = 'password' name =
> 'TXT_UserPassword'></pre>";
> echo "<br>";
> echo "<pre>\t\t<input type='submit' value='Submit
> Details'</pre>";
> echo "</form>";
>
> -----------------------------
> Michael Mason
What I usually do is set the form action to the same page as the above
code is applied to. Then I add an if statement at the top that checks the
login and redirects you to another page if login is successful. I think
you might want to give a name to your submit button as well, something
easy like name='submit'.
Then something like this at the top of the page:
if (isset($_POST["submit"])) {
...get user's password from database...
if ($_POST["password"] == $db["password"]) {
header("Location:members/index.php");
exit;
}
}
So if the login fails, they'll still be sitting at the login page. The
above code needs to be set before any HTML code, else the redirect won't
work.
http://us4.php.net/manual/en/function.header.php
--Matthew Sims
--<http://killermookie.org>