Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_REQUEST Variable

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!

like image 977
Ben Nelson Avatar asked May 17 '12 16:05

Ben Nelson


People also ask

What is the use of $_ request variable in PHP?

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.

Why do we use $_ request variable?

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 can we use $_ GET $_ POST $_ request variable in PHP?

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']).

What is the difference between $_ POST and $_ request in PHP?

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.


1 Answers

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.

like image 126
Pascal MARTIN Avatar answered Sep 19 '22 14:09

Pascal MARTIN