What's the difference between HTTP GET and POST methods? When to use methods GET and POST in HTML forms.
HTTP request methods are defined in RFC2616 Section 9 Method Definitions. These methods are also known as verbs as they indicate the desired action to be performed on an identified resource.
Understanding the basics in simple terms
From a practical point of view, these are the most simple (not so accurate) definitions and differences.
$_GET is an array of variables passed to the current script via the URL parameters. – W3schools
$_POST is an array of variables passed to the current script via the HTTP POST method. – W3schools
POST /data/form HTTP/1.1 Host: example.com name1=value1&name2=value2
When to use GET vs POST methods
In most cases:
GET should be used to retrieve data from a specified resource and sending non-sensitive data.
POST is the preferred way for sending form data.
|Can be cached|
|Remain in the browser history|
|Can be bookmarked|
|Data visible in URL|
|Used with sensitive data|
|Data length restrictions|
|ASCII data type allowed|
|Binary data type allowed|
Example: a search page should use GET, while a form that changes your password should use POST.
- When should I use GET or POST method? What’s the difference between them?
- HTTP Methods: GET vs. POST
- Methods GET and POST in HTML forms - what’s the difference?