Reputation: 3195
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.
Upvotes: 4
Views: 9983
Reputation: 11
I have encountered same problem and resolved by this:
When the form action is set as iprofile?r=search
, the request method is always GET and all input data in the form are lost. But when i set the action to iprofile/?r=search
, the request method become POST.
Maybe you can also check your action URL.
Upvotes: 1
Reputation: 14752
Simply going to a page through your browser or clicking a link IS a GET request.
Upvotes: 2
Reputation: 2944
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
)
Upvotes: 8