-3

Suppose I have a form which posts its fields like amount to say payment.php?amount=100

Instead of using

$amount=$_POST['amount'];

What if I use:

$amount=$_REQUEST['amount'];

My question is, when $_REQUEST method can be used for retrieving get as well as post variables, does the post variable sent by the form get overridden by the get variable or not?

halfer
  • 19,824
  • 17
  • 99
  • 186
Rickie
  • 611
  • 2
  • 11
  • 21

4 Answers4

6

If you are using PHP 5.3, then you can choose the $_REQUEST order. From the PHP Manual:

The request_order directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

As it says, it gives more preference for $_POST than $_GET. So if you have two same values, the $_REQUEST will take the $_POST's value instead of $_GET.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
3

POST and GET are two different super globals and they do not override each other.

The request_order configuration directive in php.ini will determine which super globals (GET, POST, COOKIE, ENV and SERVER) will be included in $_REQUEST

http://php.net/request-order

This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

In general (by default) it is set to GP. Which means that in the final _REQUEST array, POST will override GET if both exists.

Ady Romantika
  • 644
  • 1
  • 5
  • 12
1

The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive.

And

variables_order string Sets the order of the EGPCS (Environment, Get, Post, Cookie, and Server) variable parsing.

So at your case POST is at the prior.

http://php.net/manual/en/reserved.variables.request.php http://www.php.net/manual/en/ini.core.php#ini.variables-order

revo
  • 47,783
  • 14
  • 74
  • 117
1

$_REQUEST handle both $_POST and $_GET value

$_POST method is not visible to end user so he/she can not manipulate this information so it's more secure and there is no such limit of sending information as $_GET method does.

$_REQUEST method is used to receive the data of information over the data transfer on page call irrespective of data send method is...

The most important thing is $_REQUEST method is only use to read the information passed it's not used to send the information over the page call.

The speed difference should be minimal either way and of course POST overrides GET when using REQUEST

Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79