Friday, January 22, 2021

Alternative way to write PHP $_POST data

I had a situation recently where I could not write the $_POST array to a file. During debug, I learned that the $_POST data was being saved to a variable correctly, and I could output that variable to the screen, send it back as my HTTP response payload, and even write literally anything else to the file. But the $_POST array simply would not write to a local file. 

I did all my Linuxey t-shooting: checked selinux, checked PHP permissions, checked out-of-band things like inodes and disk space, but no go. 

So I changed my method to this, which worked. No clue why. Your milage may vary...

file_put_contents('test.txt', file_get_contents('php://input'));

Right to Repair finally gets a win.

"Big Ag is a particularly odious repair troll, and John Deere is its standard-bearer. The company has been trying to felonize farmers&#...