Reputation: 500
When I use POST
and GET
requests at the same time, the $_SERVER['REQUEST_METHOD']
is set to just POST.
Why is this? Is it because all requests are considered GET
in any case?
This is the request I made for the purpose of this question.
a = $("#AdminAddForm").serialize();
jQuery.post('index.php?test=yes', a);
Both $_POST and $_GET are populated after this request, and $_SERVER['REQUEST_METHOD'] set to POST.
Upvotes: 0
Views: 478
Reputation: 11597
The HTTP protocol has a first line that is called the "request line". A post looks like this:
POST http://website.com/route/whatever HTTP/1.1
... (post body)
Notice the mandatory empty line between the request line and the post body.
Now, when you also have a query string like this:
POST http://website.com/route/whatever?q=hello HTTP/1.1
... (post body)
You're mixing these things:
The HTTP request IS a POST but in PHP the stuff in the query string will end up in the $_GET global variable nonetheless.
You can have GET parameters in a HTTP POST because the HTTP protocol allows to mix the POST body with the query string.
Upvotes: 5
Reputation: 943537
When I use POST and GET requests at the same time
This is impossible.
You are, probably, making a POST request that has a query string on the URL.
PHP will populate $_GET
with data from the query string, but this has absolutely nothing to do with the request method. It is just one of PHP's weird (wrong) naming conventions.
Upvotes: 4