I have a question regarding the $_REQUEST global variable in php. When you have a get and a post submitted with the same variable name does php assign priority to either of them? Ie. if I have $_POST['var'] as well as $_GET['var'] submitted to a page would $_REQUEST['var'] contain the post or the get or would it do some other type of assignment?
Thanks!
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.
The $_REQUEST variable is used to read the data from the submitted HTML form. Sample code: Here, the $_REQUEST variable is used to read the submitted form field with the name 'username'. If the form is submitted without any value, then it will print as “Name is empty”, otherwise it will print the submitted value.
How to use it? Before you can use the the $_POST variable you have to have a form in html that has the method equal to POST. Then in the php, you can use the $_POST variable to get the data that you wanted. The $_POST syntax is ($_POST['name of the form field goes here']).
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.
It depends on the request_order
configuration directive (quoting) :
This directive describes the order in which PHP registers GET, POST and Cookie variables into the
_REQUEST
array.
Also take a look at variables_order
: some additional explanations (like the letters that can be used) are there -- and it also affects $_REQUEST
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With