ok, been toying around with this script for a while. not really a login script, just trying to get my head around this stuff.
ive got this code working to the point where if you type in the user name 'thorpe' and password 'pass' it replies with 'you passed' the same thing happens when you type the correct name / pass for 'bob'.
what i want to know is, where do i have to put my echo statements to let a user know when he has gotten the username incorrect, and also, if he gets the username correct but not the password i want it to let them know.
ie; if they type an invalid username, stop the script and
echo "invalid username";
if they get past that but type the wrong password,
echo "invalid password';
here is my code so far
$user_names = array("thorpe" => "pass","bob" => "boo");
if (isset($_POST['submit'])) {
$user_name = $_POST['user_name'];
$user_pass = $_POST['user_pass'];
foreach ($user_names as $name => $pass) {
if ($user_name == $name) {
if ($user_pass == $pass) {
echo "you passed<br />";
}
}
}
} else {
echo "<form action=".$_SERVER['PHP_SELF']." method='post' >";
echo " <input type='text' name='user_name'><br />";
echo " <input type='password' name='user_pass'><br />";
echo " <input type='submit' name='submit' value='submit'><br />";
echo "</form>";
}
im pretty sure i need to just get rid of the foreach loop, but not quite sure where to go from here, any help much appreciated.
thorpe