phpglobal-variables

Which values take precedence in $_REQUEST?


I read in the manual that $_REQUEST is an associative array consisting of cookies, get, and post arrays. I want to know which takes precedence in request array.

Say, suppose I have a variable user in $_POST as well as $_COOKIE, and if I use echo $_REQUEST['user'] then which would print. I tried it and I get the value set in $_POST. If I want to print value of $_COOKIE what should I use? I know $_COOKIE is there but still using $_REQUEST if I want to print it, then how should I do it?


Solution

  • From the PHP manual on $_REQUEST (php.net):

    Note: 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.

    In fact PHP uses the request_order config value, but falls back on variables_order if empty.

    A possible value for request or variables order might look like this: "GPC". This means that first all Get variables are associated, then the Post- and after that the Cookie variables are associated. The order is from left to right, already defined values are overwritten. Except from GET, POST and cookie values, PHP can also associate environment ("E") and server ("S") variables.

    You'll find the corresponding manual entries for the PHP config here.