I’m trying to make as basic of a login process as I can using PHP. After I submit username and password it does not appear to be running my PHP code. The form is intended to trigger the authentication process which is checking session variables to see if they match the preset values, and if so pass along another page.
I’ve tried to create it so that when you hit submit, it is checking if the correct username and password were entered. If they are, then the session variable should be set to valid/logged-in and then will bring the user to another page that greets the user with a successful login. However when I hit submit the form action occurs regardless of any information being submitted which indicates to me the PHP portion isnt functioning at all.
<?php
//start php session
session_start();
//sets username password
$username = "admin";
$password = "1234";
//check for if session value is set to logged in
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true {
header("Location: success.php");
}
//check if username & password are equal to set variables from lines 7 & 8
if (isset($_POST['username']) && isset($_POST['password'])) {
if ($_POST['username'] == $username && $_POST['password'] == $password)
{
$_SESSION['logged_in'] = true;
$_SESSION['username']=$username;
header ("Location: success.php");
}
}
?>
<html>
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #ffcc66;
}
h1{
margin: 0 auto;
width: 250px;
text-align: center;
color: #017572;
}
</style>
<h1>Login Page</h1>
<body>
<div align="center">
<form method="post" action="welcome.php">
Username:<br/>
<input type="text" name="username"><br/>
Password<br/>
<input type="password" name="password"><br/>
<input type="submit" name="submit" value="Login!">
</form>
</div>
</body>
</html>