Hello,
I am trying to make a simple PHP web page as an assignment with register and login form and I am stuck in asking PHP to verify the password when it is wrong. It basically recognizes the ID & PASSWORD when they are right and send me through to the next page but when those inforamtion above are wrong I am not able to tell it "failed login" I am a newbie and your help would be very useful. I thank you in advance.
The url: http://www.dcs.bbk.ac.uk/~pparod01/index.php
This is my code:
<?php
$username = 'username';
$password = 'password';
if (isset($_POST["username"]) && isset($_POST["password"])) {
// open text.txt for reading
$file = fopen("text.txt","r");
while (!feof($file)) {
$data = explode ("|", fgets($file));
if(isset($data[0]) && isset($data[1])){
if (trim($data[0]) == trim($_POST["username"]) && trim($data[1]) == trim($_POST["password"])) {
$login = true;
$_SESSION["login"] = $login;
$_SESSION["username"] = $_POST["username"];
//$_SESSION['type'] = $data[3];
echo "Thank you for logging in, in 5 seconds you will be taken to the homepage.";
header("refresh: 5; private.php");
break;
}
}
}
fclose($file);
}
?>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<label>Login</label>
<fieldset>
<table>
<tr align="right">
<td><label>Username:</label></td>
<td><input name="username" type="text" id="user"></td>
</tr>
<tr align="right">
<td><label>Password:</label></td>
<td><input type="password" name="password" id="pword"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" id="login" value="login">
<a href="http://www.dcs.bbk.ac.uk/~pparod01/register.php">Register</a></td>
</tr>
</table>
</fieldset>