I have made a login page in PHP without using DB. But the code doesn't seem to generate an "incorrect login" message even though it is included in the code. Upon correct login details it is redirected to a different page. Both phplogin.php and phptest.php are given below. Help appreciated
phplogin.php
<?php
session_start();
$namearray = array("raphael", "sidharth", "sony");
$passwordarray = array('123', '1234', '12345');
$name = $_POST["username"];
$password = $_POST["password"];
if (isset($_GET['logout'])) {
$_SESSION['username'] = '';
header('Location: ' . $_SERVER['PHP_SELF']);
}
if (isset($_POST['username']))
{
if (in_array($name, $namearray)) {
$key = array_search($name, $namearray);
if ($password == $passwordarray[$key]) {
function Redirect($url, $permanent = false) {
if (headers_sent() === false) {
header('Location: ' . $url, true, ($permanent === true) ? 301 : 302);
}
exit();
}
Redirect('phptest.php', false);
}
}
} else {
echo "Invalid Login";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<?php if($_SESSION['username']): ?>
<p>You are logged in as <?=$_SESSION['username']?></p>
<p><a href="?logout=1">Logout</a></p>
<?php endif; ?>
<form name="login" action="" method="post">
Username: <input type="text" name="username" value="" /><br />
Password: <input type="password" name="password" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
phptest.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>WELCOME!</p><br>
<p>You have logged in</p><br>
<a href="http://localhost/login3/phplogin.php">Logout</a>
</body>
</html>
header('Location: ' . $_SERVER['PHP_SELF']);possible header injection vulnerability