Quote:
|
Originally Posted by HHSJosh
Now I have a new question. I have set up a user authentication page, which asks for a username and password. If the correct username and password are given, I want the browser to redirect to a certain page. Hwoever, I don't know the PHP function (if there is one) that will redirect to a new page. I've searched around but I can't find anything.
|
Here's some code to do it:
PHP Code:
// ** BELOW CODE ABOVE THE <HTML> TAG!! **
$log = $_POST['login'];
$user = $_POST['username'];
$pass = $_POST['password'];
if(($log) && ($user == /* stored username */) && ($pass == /* stored password */)){
header('Location: http://the.address.to.the.redirection.com');
} else{
// login script
}
$log = $_POST['login']; - this is storing the value of "login" in a variable "$login". login is the name of the submit button of the form.
$user = $_POST['username']; - stores the entered username (in the textbox) into a variable. username is the name of the textbox.
$pass = $_POST['password']; - same as above, but subtitute the obvious.
The reason for having the if(...) case above the <HTML> tag is because since <HTML> is a header, you can't send a header after a another header (it's hard for me to explain, so just look up the "header()" function in the PHP doc.).
Your form should look something like this (assuming the form is located on a page called: "login_admin.php"):
<form action="login_admin.php" method="POST">
<input type=text name=username><br>
<input type=password name=password><br>
<input type=submit name=login value="Login">
</form>