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$_GETset, soif($_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)