I'm facing an issue where my simple dummy form doesn't pass it's session variable. There is an error code
Notice: Undefined index: username in ...login.php on line 8
Notice: Undefined index: password in ...\login.php on line 9
Wrong username or password
session start index.php
<html>
<head></head>
<body>
<?php session_start();?>
<form action="login.php" method="POST">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" value="Login">
</form>
</body>
</html>
Validation of the input will be passed on to login.php
<html>
<head></head>
<body>
<?php
session_start();
$user = "NULL";
$password = "NULL";
$user = $_REQUEST["username"];
$password = $_REQUEST["password"];
if($user == "ali" && $password == "123"){
$_SESSION["$user"] = $user;
echo "Login Successful</br>";
echo '<a href="logout.php">Logout</a>';
}
else{
echo "Wrong username or password</br>";
echo '<a href="index.php">Back</a>';
}
?>
<p>Welcome <?php echo htmlspecialchars($user) ?></p>
</body>
</html>
logout.php
<html>
<head></head>
<body>
<?php session_start();?>
<form action="login.php" method="POST">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" value="Login">
</form>
</body>
</html>