title: Saving to a file in PHP
body: <p>I have to save unique passwords and usernames to a file, but my code duplicate the first two entries, then start working properly from there. here's my code. What am I missing? I using Mac with MAMP. I'm testing the code using <code>curl</code> with this command <code>curl -d login=tenten -d passwd=peter -d submit=OK 'http://localhost:8080/php/create.php'</code></p>
  
  <pre><code>function user_exist($user_array, $user_name)
  {
      foreach ($user_array as $user) {
          if ($user['login'] === $user_name)
              return (TRUE);
  }
      return (FALSE);
  }
  
  if ($_POST['submit'] === 'OK')
  {
      if ($_POST['passwd'] != "" &amp;&amp; $_POST['login'] != "")
      {
          create_file('../private');
          if (file_exists('../private/passwd'))
          {
              $hash_passwd = hash('whirlpool', $_POST['passwd']);
              $passwds = unserialize(file_get_contents('../private/passwd'));
              if (!user_exist($passwds, $_POST['login']))
              {
                  $passwds[] = array('login' =&gt; $_POST['login'], 'passwd' =&gt; $hash_passwd);
              $serialize = serialize($passwds);
                  file_put_contents('../private/passwd', $serialize);
                  echo "OK\n";
              }
              else
              {
                  echo "ERROR\n";
              }
          }
          else
          {
              $hash_passwd = hash('whirlpool', $_POST['passwd']);
              $user_cred = array('login' =&gt; $_POST['login'], 'passwd' =&gt; $hash_passwd);
              $serialize = serialize($user_cred);
              file_put_contents('../private/passwd', $serialize);
              echo "OK\n";
          }
      }
      else
      {
          echo "ERROR\n";
      }
  }
  else
  {
      echo "ERROR\n";
  }
  </code></pre>