title: PHP Authentication using text file
body: <blockquote>
    <p>So i have fixed the problem with the loop by placing the ifelse statement outside the for loop. So when it is true it is working fine. However when FALSE i get the following error!      </p>
    
    <p>Notice: Undefined offset: 2 in webaddhidden.php on line 25 Invalid Login</p>
  </blockquote>
  
  <p>I am new to PHP and am trying to make a simple login with a text file. </p>
  
  <p>Error Message: if an incorrect username/password is entered :</p>
  
  <blockquote>
    <p>Invalid LoginInvalid LoginInvalid LoginInvalid Login Notice: Undefined offset: 2 in webaddhidden.php on line 25 Invalid Login</p>
  </blockquote>
  
  <p>and if the correct username/password the error is:</p>
  
  <blockquote>
    <p>Invalid LoginMatch Found!</p>
  </blockquote>
  
  <p>So it prints both the if and the ifelse statements. </p>
  
  <p>Your help would be much appreciated.</p>
  
  <p>Thanks!!!!</p>
  
  <p>The code I am using is:</p>
  
  <pre><code>    &lt;?php
  
      $username = $_POST['username'];
      $password = $_POST['password'];
      $matchFound = false; 
  
      $fileArray = array();
  
      $myFile = fopen("customers.txt", 'r');
  
          while(!feof($myFile) ) //reads  all lines of text file
      {
      $fileArray[] = fgets($myFile); 
      }
  
      fclose($myFile);
  
      for($lineCounter = 0; $lineCounter &lt; count($fileArray); $lineCounter++)
          {
            $exploadedLine = explode("\t",$fileArray[$lineCounter]);
  
            if(trim($exploadedLine[2] == $username &amp;&amp; trim($exploadedLine[3]) 
                     == $password))
          {
  
              echo 'Match Found!';
      $matchFound = true;
      break;
  
              }
  
          elseif($matchFound == false)
          {
      echo 'Invalid Login';
          }
  
        }
  </code></pre>
  
  <p>?></p>