title: Create or write/append in text file
body: <p>I have a website that every time a user logs in or logs out I save it to a text file.</p>
  
  <p>My code doesn't work in appending data or creating a text file if it does not exist.. Here is the sample code</p>
  
  <pre><code>$myfile = fopen("logs.txt", "wr") or die("Unable to open file!");
  $txt = "user id date";
  fwrite($myfile, $txt);
  fclose($myfile);
  </code></pre>
  
  <p>It seems it does not append to next line after I open it again.</p>
  
  <p>Also I think it would also have an error in a situation when 2 users login at the same time, would it affect opening the text file and saving it afterwards?</p>