I am trying to write a very basic registration module for blueimp.net’s AjaxChat. I have a script that writes to the user config file.
$userfile = "lib/data/users.php";
$fh = fopen($userfile, 'a');
$addUser = "string_for_new_user";
fwrite($fh, $addUser);
fclose($fh);
But I need it to insert $addUser before the very last line, which is ?>
How would I accomplish this using fseek?
If you always know that the file ends with ?> and nothing more, you can:
To further enhance the answer: you’re going to want to open your file in mode
r+because of the following note regardingfseek:fseek($fh, -2, SEEK_END)will place the position at the end of the file, and then move it backwards by 2 bytes (the length of?>)