How can I check if the request is a post back in PHP, is the below ok?
if (isset($_POST["submit"]))
where submit
is the name
of the <input type="submit" />
That will work if you know and expect such a submit button on the same page.
If you don't immediately know anything about the request variables, another way is to check the request method:
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
As pointed out in the comments, to specifically check for a postback and not just any POST request, you need to ensure that the referrer is the same page as the processing page. Something like this:
if (basename($_SERVER['HTTP_REFERER']) == $_SERVER['SCRIPT_NAME'])
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