So for an assignment (hence why I'm storing usernames and pw in a .txt file), I need to create a login page where a user inputs his username and password. The "form" is then sent to a sessionOpen.php file to process if the username and password are contained within a login.txt file.
Here's my sessionOpen.php code:
<?php
$myFile = "login.txt";
$contents = file_get_contents($myFile);
$contents = explode("\n", $contents);
foreach($contents as $values){
$loginInfo = explode(":", $values);
$user = $loginInfo[0];
$password = $loginInfo[1];
if($user == $_POST['username'] && $password == $_POST['password']){
session_start();
header('Location: browse.php');
}
else{
echo '<script>alert("Please verify your username and password.");</script>'
}
}
?>
Inside the login.txt file, usernames and password follow the format of user1:password1, hence why the explode(":", $values)
So normally a session should be created so that the user can now access pages on the website that are locked to people that own an account. The code is not working.
Here is the form if it helps:
<form action="sessionOpen.php" method="post">
<h2>Username:</h2><input type="text" id="username"><br>
<h2>Password:</h2><input type="password" id="password"><br>
<input type="submit" value ="submit">
<input type="reset" value ="reset">
</form>