When using php code to receive parameters, $_POST, $_GET and $_REQUEST are often used to receive front-end data. They are all built-in global variables in php, so what are their uses and differences?
1. $_GET variable
The $_GET variable can be used to obtain form data submitted by get. Usually, the form parameters are attached to the URL link of the action attribute, and the fields and values are in one-to-one correspondence.
Example:
xxxx.xxx.xxx/tit.php?c=1&b=2
The parameter c value of the tit.php file is 1, and the parameter b value is 2
Then the backend receives:
<?php
print_r($_GET);
echo $_GET['c'];
?>
Among them, $_GET is to receive all the parameters submitted by get, and the result is in array format, and $_GET['c'] is to obtain only the value of the parameter c of the submitted form.
Use the get method to submit data because you can directly view the parameters and values in the url link, you can use to create a text link list and other methods to create multiple parameters in batches, the security is not high, and the amount of transmitted data cannot be larger than 2kb .
2. $_POST variable
The $_POST variable can be used to retrieve data submitted using the post method. Unlike $_GET, it does not pass parameters through a link.
aa:111,bb:222
The POST method generally stores the fields in the form in the HTTP HEADER and transmits them to the specified address through the HTTP post mechanism, which cannot be viewed directly. limit.
Example:
<?php
print_r($_POST);
echo $_GET['parameters'];
?>
The usage of $_POST is the same as $_GET, $_POST can get the data array submitted by post, and $_GET['parameter'] can get the value of the specified parameter.
3. $_REQUEST variable
Similar to the above two variables, the $_REQUEST variable can obtain all the parameter data submitted by the get and post methods, but the speed is slower than that of $_GET and $_POST. The usage methods are basically the same as them.
Example:
<?php
print_r($_REQUEST);
echo $_REQUEST['parameters'];
?>
$_GET, $_POST, $_REQUEST can use the ["parameter"] method to get the value of the specified parameter, $_GET, $_POST can only get the data submitted in a single way of get, post, and $_REQUEST is applicable to two a way.