For a school project I have been asked to create a login system for a website. The language I have to use is PHP with no database as of yet (for a later assignment). I'm just wondering if this code has any security flaws.
Here is my current code:
Navigation.php note that this is to be included in another html document.
<link type="text/css" rel="stylesheet" href="style_nav.css">
<ul>
<li><a href="index.php">Index</a></li>
<li><a href="test.php">Test</a></li>
<li><a href="#">not-in-use</a></li>
</ul>
<div class="login" >
<?php
session_start();
$_SESSION['last_phage'] = $_SERVER['PHP_SELF'];
if (empty($_SESSION['user'])) {
echo '
<form action="login.php" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Login">
</form>';
} else {
echo 'Welcome! ' . $_SESSION['user'] . '<form action="login.php" method="POST"><input type="submit" value="logout" name="logout"></form>';
}
?>
</div>
<br />
<br />
<hr />
Login.php
<?php
session_start();
if (isset($_POST['logout'])) {
session_destroy();
header("Location: index.php");
}
if (isset($_POST['username']) && isset($_POST['password'])) {
if (!empty($_POST['username']) && !empty($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if ($username == 'kad' && $password == 'lol') { //this is just temporary without a database
$_SESSION['user'] = $username;
header("Location:" . $_SESSION['last_phage']);
}
header("Location: " . $_SESSION['last_phage']);
}
}
?>