I find myself working through a lot of other peoples' code nowadays. I noticed if (isset($_POST)) in some of the code and made sure to fix that. (It will always evaluate true). Then I start seeing this:
if ($_POST)
After thinking through this, it annoys me, but still seems to work. Does anyone see any issues with using this to check if a form has been submitted? If the $_POST array is empty, then it evaluates as false. Any special cases where this might not work?
It's an unreliable test - it assumes that at least one form element will be submitted. It's entirely possible to perform a POST where no data is submitted, which would make if ($_POST) evaluate to false, but be meta-false as a POST was actually performed.
The proper 100% reliable test is
if ($_SERVER['REQUEST_METHOD'] == 'POST') { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With