When you've just sent a form then refresh, if you haven't used the Post/Redirect/Get pattern, Firefox will ask you if you want to resend your form data. If you click Resend, the page would normally reload and the form processing code would do its thing again.
In production, usually, I redirect so this doesn't happen. While developing, though, it can be very useful to be able to refresh and see my debug dumps with the same post data as my code changes, without having to fill the form again or use a tool such as Postman. Just fill the form, die()
before the redirect, and test away.
In the last few months, it seems something changed, and Firefox now only pretends to resend the data on a refresh. It still asks me, but even when the following code is the very first thing executed, $_POST
is an empty array.
<?php
echo '<pre>';
var_dump($_POST);
echo '</pre>';
die();
?>
Meanwhile, following the same steps on Chrome does give me back my $_POST array like it used to.
I was away from work for several months, so I'm not sure what changed, but since using Firefox in Safe Mode (without add-ons) yields the same result, I'm almost sure the issue is there. I use Firefox 75 on Mac.
Is there a hidden preference that changes the behaviour of resending POST data on refresh? Can I fix this?
History.replaceState
can prevent POST request being repeated.