title: PHP: Adding text to a file
body: <p>I'm trying to set up authentication on my server, however, I know little about Php.</p>
  
  <p>I have a php file filled with users and passwords:</p>
  
  <pre><code> function getPassword( $user )
   {
      // the user/password database. For very small groups
      // of users, you may just get away with expanding this
      // array.
      $passwords= array (
          'user1' =&gt; 'password1',
          'user2' =&gt; 'password2',
          'user3' =&gt; 'password3',
          'user4' =&gt; 'password4'
           );
      $password = $passwords[ $user ];
      if ( NULL == $password )
          return NULL;
  </code></pre>
  
  <p>Without manually editing the array of passwords, I want a php file to read in user inputs for usernames and passwords and append it to the array.</p>
  
  <p>I have a vague idea of how this could work by looking up documentation:</p>
  
  <pre><code>&lt;?php
  function fwrite_stream($fp, $string) {
      $fp = fopen('shit.php', 'w');
      for ($written = 0; $written &lt; strlen($string); $written += $fwrite) {
          $fwrite = fwrite($fp, substr($string, $written));
          if ($fwrite === false) {
              return $written;
          }
      }
      return $written;
      fclose($fp);
  }
  ?&gt;
  </code></pre>
  
  <p>How do I tell this to write to the array? </p>