1// LOCK_EX will prevent anyone else writing to the file at the same time
2// PHP_EOL will add linebreak after each line
3$txt = "data-to-add";
4$myfile = file_put_contents('logs.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
5
6// Second option is this
7$myfile = fopen("logs.txt", "a") or die("Unable to open file!");
8$txt = "user id date";
9fwrite($myfile, "\n". $txt);
10fclose($myfile);
1$log_content="This line is logged on 2020-08-14 09:55:00";
2$myfile = fopen("log.txt", "a") or die("Unable to open file!");
3fwrite($myfile, $log_content);
4fclose($myfile);