title: PHP Read txt file and check if username password exists
body: <p>I have a bunch of passwords and usernames stored in a txt file and i need to check for matches. I know this is not a safe method but its for leaning purposes.</p>
  
  <p>This code writes the usernames and passwords to a txt file</p>
  
  <pre><code>  if(isset($_POST['register'])) //  
     {
      $user  = $_POST['username'];
      $password=$_POST['password'].PHP_EOL;
      $fh = fopen("file.txt","a+");
      fwrite($fh,$user." ".$password); //write to txtfile
  
      fclose($fh);
   }
  </code></pre>
  
  <p>Here's the code im having trouble with. </p>
  
  <p>Username and Passwords are stored like this in results</p>
  
  <pre><code>      username1 passwords1 username2 password2 etc. 
  </code></pre>
  
  <p>So I need to check if result[0] = userinput AND if it exists check if result[1] = passwordInput and so on.</p>
  
  <pre><code>   if(isset($_POST['Logg']))
     {
     //$_SESSION['username']=$user; 
     //$_SESSION['password']=$password;
  
      $file = file_get_contents("file.txt"); // Returns a string
  
      $result = explode(" ",$file);
      $boolC= false;
  
      for($i=0; $i&lt; count($result); $i++)
      {
     if($result[$i] === $user)
     {
      $boolC=true;
      $i =$i+1; 
      if($boolC === true)
      {
          if($result[$i]===$password)
          {
              echo 'Password and Username Correct';
          }
      }
  
     }
       }
  
    }
  </code></pre>