Verifying username and password stored in .txt file for login in PHP
<p>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.</p>

<p>Here's my sessionOpen.php code:</p>

<pre><code>    &lt;?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'] &amp;&amp; $password == $_POST['password']){
        session_start(); 
        header('Location: browse.php');
   }
    else{
        echo '&lt;script&gt;alert("Please verify your username and password.");&lt;/script&gt;'
    }
}
    ?&gt;
</code></pre>

<p>Inside the login.txt file, usernames and password follow the format of <code>user1:password1</code>, hence why the <code>explode(":", $values)</code> </p>

<p>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. </p>

<p>Here is the form if it helps:</p>

<pre><code>&lt;form action="sessionOpen.php" method="post"&gt;
   &lt;h2&gt;Username:&lt;/h2&gt;&lt;input type="text" id="username"&gt;&lt;br&gt;
   &lt;h2&gt;Password:&lt;/h2&gt;&lt;input type="password" id="password"&gt;&lt;br&gt;
   &lt;input type="submit" value ="submit"&gt;
    &lt;input type="reset" value ="reset"&gt;
&lt;/form&gt;
</code></pre>