Login Script Not working
Posted: Sun Jan 16, 2011 3:35 pm
Hi all. Please help me with this one - I'm a noob so it's probably really simple!
I have the following script that shows a login form, takes only the username at the moment, and compares it against a flat-file DB. It doesn't work. No matter whether I enter the correct username or not, it resets the form. If the username is wrong, it doesn't even show the message!
Here it is:
Please help a noob!
I have the following script that shows a login form, takes only the username at the moment, and compares it against a flat-file DB. It doesn't work. No matter whether I enter the correct username or not, it resets the form. If the username is wrong, it doesn't even show the message!
Here it is:
Code: Select all
<font face="arial">
<?php
$usernames = file('username.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$passwords = file('password.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
showform();
function showform($message) {
?>
<html>
<head>
<title>Authentication Required</title>
</head>
<style>
input { border: 1px solid grey; }
error { color: red }
</style>
<form action="readlines.php" method="POST">
<error><?php echo($message); ?></error>
<p>Username:<br /><input type="text" name="user"/></p>
<p>Password:<br /><input type="password" name="pass"/></p>
<p><input type="submit" value="Login"/></p>
</form>
</html>
<?php
die();
}
$user = $_POST[user];
$pass = $_POST[pass];
while ($flag != "loggedin")
{
searcharray($usernames, $user);
function searcharray($array, $item) {
$linenum = 0;
while ($array[$linenum] != "")
{
if ($array[$linenum] == $item)
{
$flag = "loggedin";
}
$linenum = $linenum + 1;
}
showform("Incorrect login details!");
}
}
echo("end of script"); //for testing purposes
?>
</font>