samedi 7 juin 2014

How do I set whether a form redirects to a new page or not?


Vote count:

0




So I'm trying to create a simple log in page with php and html. It's pretty simple. First, a user inputs their username and their password, then clicks the submit button.


If the username/password combo is invalid, "Invalid log in." is printed, and the user is redirected back to the log in page.

If the username/password combo is valid, "Logging you in..." is printed, and the user is redirected to another page. All POST data must be kept when redirecting.


I can't figure out how to change the form's action.


Code snippet below. Please look past potential SQL injections. I will deal with them later.



<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" id="form">

User Name:<input type="text" name="userName" id="userName">
Password:<input type="password" name="password" id="password">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="reset" id="reset" value="Reset">

<?php
$username = $_POST['userName'];
$password = $_POST['password'];
//(omitted) function that checks whether the credentials are valid or not
if (password_verify($password, $hash)) {
echo "Logging you in...";
//TODO: function that redirects user to another page
}
else {
echo "Invalid log in.";
}
?>


asked 3 mins ago






Aucun commentaire:

Enregistrer un commentaire