I am bit confusing about these super global variable ($_POST, $_GET, $_REQUEST
) in php
. I want to know which scenario do I need to use these variable in php
and what are the main differences these three stand for ?
问题:
回答1:
$_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 $_COOKIE (depending on request_order=
)
回答2:
Difference is:
$_GET retrieves variables from the querystring, or your URL.> $_POST retrieves variables from a POST method, such as (generally) forms. $_REQUEST is a merging of $_GET and $_POST where $_POST overrides $_GET.
回答3:
Well to know better please visit http://www.diffen.com/difference/GET-vs-POST-HTTP-Requests
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
.
Hope it helps.