How to save a POST request to a file

I’ll give a couple of examples of saving the data of the incoming POST request to a file:

Option 1

$s = implode('|', $_POST);
exec('echo $s >> file.txt');

Option 2

file_put_contents('file.txt', json_encode($_POST));

Example of option 2 with a specific parameter:

file_put_contents('file.txt', json_encode($_POST['parameter']));
Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply