$_REQUEST
(PHP 4 >= 4.1.0, PHP 5)
$_REQUEST — HTTP Request variables
Description
An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.
Changelog
Version | Description |
---|---|
5.3.0 | Introduced request_order. This directive affects the contents of $_REQUEST. |
4.3.0 | $_FILES information was removed from $_REQUEST. |
4.1.0 | Introduced $_REQUEST. |
Notes
Note:
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.
Note:
When running on the command line , this will not include the argv and argc entries; these are present in the $_SERVER array.
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.
See Also
- import_request_variables() - Import GET/POST/Cookie variables into the global scope
- Handling external variables
- The filter extension
- Функция Суперглобальные переменные() - Суперглобальные переменные - это встроенные переменные, которые всегда доступны во всех областях видимости
- Функция $GLOBALS() - Ссылки на все переменные глобальной области видимости
- Функция $_SERVER() - Информация о сервере и среде исполнения
- Функция $_GET() - GET-переменные HTTP
- Функция $_POST() - HTTP POST variables
- Функция $_FILES() - Переменные файлов, загруженных по HTTP
- Функция $_REQUEST() - Переменные HTTP-запроса
- Функция $_SESSION() - Переменные сессии
- Функция $_ENV() - Переменные окружения
- Функция $_COOKIE() - HTTP Куки
- Функция $php_errormsg() - Предыдущее сообщение об ошибке
- Функция $HTTP_RAW_POST_DATA() - Необработанные POST-данные
- Функция $http_response_header() - Заголовки ответов HTTP
- Функция $argc() - Количество аргументов переданных скрипту
- Функция $argv() - Массив переданных скрипту аргументов
Коментарии
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:
}
?>
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.
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
In PHP version 7.0 with the default settings.+, $_REQUEST array does not contain cookies.