Selecting $_GET or $_POST depending on the request method isn't a general solution, since it's possible for an HTTP request to have both posted content and a query string in the URI.
If you want to allow for this possibility, you can use
<?php
$req = array_merge($_GET, $_POST);
?>
or vice versa, depending on which you want to be used in the event of a clash between them.
$_REQUEST
$_REQUEST — HTTP Request-Variablen
Beschreibung
Ein assoziatives Array, das standardmäßig den Inhalt von $_GET, $_POST und $_COOKIE enthält.
Changelog
| Version | Beschreibung |
|---|---|
| 5.3.0 | request_order eingeführt. Die Direktive wirkt sich auf den Inhalt von $_REQUEST aus. |
| 4.3.0 | $_FILES-Informationen aus $_REQUEST entfernt. |
| 4.1.0 | $_REQUEST eingeführt. |
Anmerkungen
Hinweis: Dies ist eine 'Superglobale' oder automatisch globale Variable. Dies bedeutet, dass sie innerhalb des Skripts in jedem Geltungsbereich sichtbar ist. Es ist nicht nötig, sie mit global $variable bekannt zu machen, um aus Funktionen oder Methoden darauf zuzugreifen.
Hinweis: Wenn das Skript auf der Kommandozeile ausgeführt wird, enthält die Variable nicht den Inhalt von argv und argc; diese finden sich im Array $_SERVER.
Hinweis: Die Variablen in $_REQUEST werden dem Skript mittels der GET-, POST- und COOKIE-Inputmechanismen zur Verfügung gestellt. Daher kann der Inhalt durch einen entfernten Benutzer modifiziert worden sein und ist daher als nicht vertrauenswürdig zu betrachten. Das Vorhandensein und die Reihenfolge des Variableninhalts in diesem Array wird entsprechend der PHP-Konfigurationsdirektive variables_order bestimmt.
Siehe auch
- import_request_variables() - Import GET/POST/Cookie variables into the global scope
- Behandlung externer Variablen
- Die Filter-Erweiterung
$_REQUEST
13-Aug-2009 10:56
17-Jul-2008 03:04
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:
}
?>
