Been doing a bit of digging about this, but, no luck finding information
I'm trying to check whether a form has been submitted and if it is either GET
or POST
. So essentially I use:
if($_SERVER['REQUEST_METHOD'] == 'GET')
or
if($_SERVER['REQUEST_METHOD'] == 'POST')
However, I find that if I don't submit any form, and just go to the page directly - a simple HTTP Request, the REQUEST_METHOD
is GET
. What gives? Is this by design? If so then I can't use the former statement to check whether a form has been submitted via GET. Seems a bit redundant...
Someone with a bit more knowledge please explain this to me, that would be appreciated. Thanks.
Basically most HTTP requests are GET requests.
you can use if($_POST)
to check if it's a POST. (That's the array with POST data in it. All pages have $_GET
set, so if($_GET)
won't work to tell if it's a GET)
However, if(count($_GET)>0)
will tell you if there is $_GET data.
You can have both POST and GET data though, by sending a POST request to a URL with GET data in it (i.e. http://example.unreal?GetData=4&OtherData=no
)
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