Search code examples
phppostget

What is the meaning of "a POST request also has $_GET parameters"


Hi i am looking at differences between $_GET and $_POST methods , i came across some articles that says

  • A POST request also has $_GET parameters

  • So a POST request is a superset of a GET request; you can use $_GET in a POST request, and it may even make sense to have parameters with the same name in $_POST and $_GET that mean different things.

When should I use GET or POST method? What's the difference between them?

http://www.sitepoint.com/on-get-and-post/

And there is an example also

For example, let's say you have a form for editing an article. The article-id may be in the query string (and, so, available through $_GET['id']), but let's say that you want to change the article-id. The new id may then be present in the request body ($_POST['id']).

so how can we use $_GET['id'] and $_POST['id'] at the same time , confusing . Please explain this with a simple example . so everyone including me , who does not understand this can understand well .

Thank you in advance :)


Solution

  • Perhaps the simplest way to understand this is that $_GET is simply badly named. All it actually represents is the values of "query string" parameters parsed from the part of a URL after a ?. Since every request has a URL, whatever type it is, any request can populate $_GET.

    $_POST, on the other hand, is populated only for POST requests, and even then only those whose request body is in a particular format.

    When you use method=get in HTML, the browser just creates a URL based on the form data, and asks for that URL with a GET request the same as you typing it into the address bar. With method=post, the form data is sent separately from the URL, but the URL might still contain a ? and a query string.