0
votes

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.

2
This is in my opinion a good source: Tuts+. Mind that asking for opinions is off-topic on SO.pid
"When I use POST and GET" - please show the relevant code where you do this.CodeCaster
Why do you consider this asking for an opinion? I want to understand the subject, I am assuming there is one true answer.Lexib0y

2 Answers

5
votes

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 method POST;
  • the body of the POST (containing the form's content);
  • the query string.

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.

4
votes

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.