title: How to compare two string fields in PHP
body: <p>I am a login/register page and I have this for my login:</p>
  <pre><code>session_start();
  
  $username = $_POST[&quot;username&quot;];
  $password = $_POST[&quot;password&quot;];
  
  $user_infile = &quot;&quot;;
  $password_infile = &quot;&quot;;
  
  $user_data = fopen(&quot;user_data.txt&quot;, &quot;r&quot;);
  
  while(! feof($user_data)){
      $userArray = fgetcsv($user_data);
  
      if ($userArray[0] == $username){
          $user_infile = $userArray[0];
          $password_infile = $userArray[1];
      }
      
  }
  
  if (strval($password)  ==  strval($password_infile)){
      $_SESSION[&quot;loggedin&quot;] = true;
      $_SESSION[&quot;username&quot;] = $username;
      $_SESSION[&quot;password&quot;] = $password;
      header('Location: home.php');
      exit();
  }
  else{
      header('Location: error.php');  
      exit();
  }
  </code></pre>
  <p>The login works perfect if the password is numeric i.e 123, but if password contains characters ie abc, the comparison fails and the else statement is executed. I used strval to convert both to string, but didnt work. I simply used password == password, that didnt work too. strcmp also didnt work. Am I missing something here?</p>
  <p>Edit:
  This is the input file:</p>
  <pre><code>new, 123, 0
  admin, pass, 0
  jon, a1, 0
  </code></pre>