Create or write/append in text file

I have a website that every time a user logs in or logs out I save it to a text file.

My code doesn’t work in appending data or creating a text file if it does not exist.. Here is the sample code

$myfile = fopen("logs.txt", "wr") or die("Unable to open file!");
$txt = "user id date";
fwrite($myfile, $txt);
fclose($myfile);

It seems it does not append to next line after I open it again.

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?

7 Answers
7

Leave a Comment