I have a form which have two values, user and pass when submitted.
$_POST['submit'] = the name of the submit button is "submit"
When the user submits I have the following script in php to validate:
$logins = array(
'user1' => 'pass1',
'user2' => 'pass2',
'user3' => 'pass3'
);
foreach($_POST as $key => $value) {
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
/******************************************************************************/
if (isset($_POST['submit'])){
$user = isset($_POST['user']) ? strtolower($_POST['user']) : '';
$pass = isset($_POST['pass']) ? $_POST['pass'] : '';
$report = $_POST['typereport'];
if ($logins[$user] != $pass) {
showForm("Wrong Username/Password");
exit();
}
else {
if ($report == "Clinical") {
$file = $filename;
$contents = file($file);
$string = implode("<br>", $contents);
echo "<head><title>ScoreViewer: Clinical</title></head>";
echo "Logged in as: " . strtoupper($user) . "<br>";
echo "<a href='log2.php'>Sign Out</a>";
echo "<br><br>";
echo "<pre>" . $string . "</pre>";
echo "<br><br>";
}
elseif ($report == "Non-Clinical") {
$file = $filename2;
$contents = file($file);
$string = implode("<br>", $contents);
echo "<head><title>ScoreViewer: Non-Clinical</title></head>";
echo "Logged in as: " . strtoupper($user) . "<br>";
echo "<a href='log2.php'>Sign Out</a>";
echo "<br><br>";
echo "<pre>" . $string . "</pre>";
echo "<br><br>";
}
}
} else {
showForm();
exit();
}
Now what will happen is, the script will compare the username and password entered to find a match. If a match is found and based of what type of report it is, it will display. But for some reason whenever the submit button is pressed it goes directly to the Clinical portion of the IF statement.
If i just use a single username/password without arrays it works fine. Like the following:
$username = "user";
$password = "pass";
foreach($_POST as $key => $value) {
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
/******************************************************************************/
if (isset($_POST['submit'])){
$user = isset($_POST['user']) ? strtolower($_POST['user']) : '';
$pass = isset($_POST['pass']) ? $_POST['pass'] : '';
$report = $_POST['typereport'];
if ($user != $username && $pass != $password) { #$logins[$user] != $pass) {
showForm("Wrong Username/Password");
exit();
}
else {
// decide what to do here if the user and pass is correct, deleted to save space
}
} else {
showForm();
exit();
}
How do I achieve what i am trying to complete?
Full HTML CODE: Pastbin