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:
}
?>
$_REQUEST
(No version information available, might be only in CVS)
$_REQUEST — Variables de requête HTTP
Description
Un tableau associatif qui, par défaut, contient le contenu de $_GET, $_POST et $_COOKIE.
Historique
| Version | Description |
|---|---|
| 5.3.0 | Introduction de request_order. Cette directive affecte le contenu de la variable $_REQUEST. |
| 4.3.0 | $_FILES a été supprimé de $_REQUEST. |
| 4.1.0 | Introduction de $_REQUEST. |
Notes
Note: Ceci est une 'superglobale', ou variable globale automatique. Cela signifie simplement que cette variable est disponible dans tous les contextes du script. Il n'est pas nécessaire de faire global $variable; pour y accéder dans les fonctions ou les méthodes.
Note: En ligne de commande, cette variable n'inclut pas les variables argv et argc : elles sont stockées dans le tableau $_SERVER.
Note: Les variables fournies au script via le méchanisme d'entrée GET, POST, et COOKIE ne doivent recevoir qu'une confiance limitée. La présence et la valeur des entrées de ce tableau sont réglés par la directive variables_order.
$_REQUEST
17-Jul-2008 11:04
22-May-2008 10:05
POST has priority over GET.
If you POST and GET the same variable with different values, the POST value will be the one used in the REQUEST variable.
EX:
<?PHP
if(isset($_GET['posted']) == 1)
{
echo "POST: ";
print_R($_POST);
echo "<br/>GET: ";
print_R($_GET);
echo "<br/>REQUEST: ";
print_R($_REQUEST);
}
else
{
?>
<form method="post" action="?posted=1&something=someotherval">
<input type="text" value="someval" name="something"/>
<input type="submit" value="Click"/>
</form>
<?
}
?>
The above form post will result in the following output:
POST: Array ( [something] => someval )
GET: Array ( [posted] => 1 [something] => someotherval )
REQUEST: Array ( [posted] => 1 [something] => someval )
