PHP 8.3.4 Released!

$_REQUEST

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

$_REQUESTVariables HTTP Request

Descripción

Un array asociativo que por defecto contiene el contenido de $_GET, $_POST y $_COOKIE.

Notas

Nota:

Esta es una 'superglobal' o una variable automatic global. Significa simplemente que es una variable que está disponible en cualquier parte del script. No hace falta hacer global $variable; para acceder a la misma desde funciones o métodos.

Nota:

Cuando se ejecuta en la línea de comandos , no se incluirán las entradas argv y argc; ya que están presentes en el array $_SERVER

Nota:

Las variables en $_REQUEST se proporcionan al script a través de los mecanismos de entrada GET, POST, y COOKIE y por lo tanto pueden ser manipulados por el usuario remoto y no debe confiar en el contenido. La presencia y el orden de las variables listadas en este array se definen según la directiva de configuración PHP request_order, y variables_order.

add a note

User Contributed Notes 5 notes

up
189
strata_ranger at hotmail dot com
15 years ago
Don't forget, because $_REQUEST is a different variable than $_GET and $_POST, it is treated as such in PHP -- modifying $_GET or $_POST elements at runtime will not affect the ellements in $_REQUEST, nor vice versa.

e.g:

<?php

$_GET
['foo'] = 'a';
$_POST['bar'] = 'b';
var_dump($_GET); // Element 'foo' is string(1) "a"
var_dump($_POST); // Element 'bar' is string(1) "b"
var_dump($_REQUEST); // Does not contain elements 'foo' or 'bar'

?>

If you want to evaluate $_GET and $_POST variables by a single token without including $_COOKIE in the mix, use $_SERVER['REQUEST_METHOD'] to identify the method used and set up a switch block accordingly, e.g:

<?php

switch($_SERVER['REQUEST_METHOD'])
{
case
'GET': $the_request = &$_GET; break;
case
'POST': $the_request = &$_POST; break;
.
.
// Etc.
.
default:
}
?>
up
21
mike o.
14 years ago
The default php.ini on your system as of in PHP 5.3.0 may exclude cookies from $_REQUEST. The request_order ini directive specifies what goes in the $_REQUEST array; if that does not exist, then the variables_order directive does. Your distribution's php.ini may exclude cookies by default, so beware.
up
2
codeblog.pro
3 years ago
In PHP version 7.0 with the default settings.+, $_REQUEST array does not contain cookies.
up
1
Luke Madhanga
7 years ago
To access $_POST, $_GET, etc, use the function filter_input(TYPE, varname, filter) to ensure that your data is clean.

Also, I was brought up to believe that modifying superglobals is a BAD idea. I stand by this belief and would recommend you do too
up
-44
Filomena
3 years ago
Warning:

The way $_REQUEST is populated by default can lead to strange bugs because of the unfortunate default setting of the configuration directive 'variables_order'.

Example: In an e-shop you want to display prices based on user preference. User can either switch the currency or the previous selection is used. By defaut, the following code WILL NOT WORK as expected:

<?php
if ($_REQUEST['currency']) # change currency on user request
{
$currency = $_REQUEST['currency']; # use it
setcookie('currency', $_REQUEST['currency'], 0, 'eshop.php'); # store it
}
else
# use default currency
{
$currency = 'USD';
}

# display shop contents with user selected currency
echo 'All prices are shown in ', $currency;

# let the user switch currency
echo '<a href="eshop.php?currency=USD">Switch to USD</a>';
echo
'<a href="eshop.php?currency=EUR">Switch to EUR</a>';
?>

Regardless of the user choice, the cookie value is used, so unless you change the default 'request_order' or 'variables_order' the $_REQUEST[something] variable is stuck with the cookie value forever regardless of the user 'REQUEST'.

Fix 1:

<?php
ini_set
('request_order', 'CGP'); # use previous value (stored in cookie) or new value upon user request
.
.
.
?>

Fix 2:
Be very careful and patient and go with $_GET, $_POST and $_COOKIE instead of the convenient $_REQUEST. Good luck.
To Top