I am bit confused about these super global variable ($_POST
, $_GET
, and $_REQUEST
) in PHP. In which scenario do I need to use these variables in PHP, and what are the main differences these three stand for?
$_POST is an associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request. You can use when you are sending large data to server or if you have sensitive information like passwords, credit card details etc
$_GET is an associative array of variables passed to the current script via the URL parameters. you can use when there is small amount of data, it is mostly used in pagination, page number is shown in the url and you can easily get the page number from URL using $_GET
$_REQUEST is a 'superglobal' or automatic global, variable. This simply means that it is available in all scopes throughout a script. It is an associative array that by default contains the contents of $_GET, $_POST and $_REQUEST (depending on request_order=
)
$_COOKIE
shouldn't be stroken over. Either delete it or specify for which versions of PHP it is valid for (or some other explanation, whatever is true). –
Centenarian $GLOBALS, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST, $_ENV
as documented here: php.net/manual/en/language.variables.superglobals.php –
Dre Difference is:
$_GET retrieves variables from the query string, or your URL.
$_POST retrieves variables from the request body, in case it was encoded using either application/x-www-form-urlencoded or multipart/form-data encoding.
$_REQUEST is a merging of $_GET, $_POST and $_COOKIE where order of overriding values with same keys is defined in PHP configuration.
$_REQUEST
behaviour is determined by the request_order
and variables_order
configuration directives. –
Geriatric $_REQUEST
Also includes values in the $_COOKIE
super global ;) php.net/manual/en/reserved.variables.request.php –
Barbette request_order
)? I am beginning to think REQUEST ain't that useful. When would u use it? –
Renfred $_REQUEST
." from a comment here: php.net/manual/en/reserved.variables.request.php –
Dre There are 2 methods to send HTML form data from 1 Page to another or HTML page to server side (In PHP).
POST
It is a method in which data gets sent using packet which is not visible to any user on web-browser. it is secured compared to GET method.
GET
It is a method in which data gets sent with URL which is visible to user in address-bar of any web-browser. So, it’s not secure as POST method.
Now, There are total three super global variables to catch this data in PHP.
$_POST
: It can catch the data which is sent using POST method.$_GET
: It can catch the data which is sent using GET method.$_REQUEST
: It can catch the data which is sent using both POST & GET methods.
Also with $_GET
superglobal variable can collect data sent in the URL from submit button.
Well, to know better, please visit GET vs. POST:
1) Both
$_GET
and$_POST
create an array e.g.array( key => value, key2 => value2, key3 => value3, ...)
. This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.2) Both
GET
andPOST
are treated as$_GET
and$_POST
. These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.3)
$_GET
is an array of variables passed to the current script via the URL parameters.4)
$_POST
is an array of variables passed to the current script via the HTTP POST method.---- whereas
$_REQUEST
contains$_POST
,$_GET
and$_COOKIE
.
$GET : When you use GET method, your paramethers and requests will appear on URL adress
$POST:
If you use POST method, doesnt
Also POST methods safer than GET methods
$_POST hides the variables/values (they cannot be seen), whereas $_GET shows them! If the values include passwords or other sensible info, it's advisable to use $_POST.
© 2022 - 2025 — McMap. All rights reserved.
$_REQUEST
– Geriatric