downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

$_SESSION> <$_FILES
[edit] Last updated: Fri, 18 Sep 2009

view this page in

$_REQUEST

$_REQUESTПроменливи от HTTP заявката

Описание

Асоциативен масив, съдържащ елементите на $_GET, $_POST и $_COOKIE.

Дневник на промените

Версия Описание
5.3.0 Въведена е request_order. Тази директива повлиява съдържанието на $_REQUEST.
4.3.0 Информацията за $_FILES е премахната от $_REQUEST.
4.1.0 Въведена е $_REQUEST.

Бележки

Забележка: Това е 'свръхглобална' или автоматично глобална променлива. Това просто означава, че тя е налична във всички обхвати навсякъде из скрипта. Не е нобходимо да правите global $variable;, за да я достъпвате от тялото на функции и методи.

Забележка: При работа на командния ред , argv и argc няма да бъдат включени в масива $_REQUEST. Те са налични в $_SERVER.

Забележка: Променливите в $_REQUEST са предоставени на скрипта посредством входящите механизми GET, POST и COOKIE и следователно биха могли да бъдат променяни от отдалечения потребител, което означава, че на тях не може да се има доверие. Наличието и редът на включване на променливи в този масив се дефинират съгласно конфигурационната директива на PHP variables_order.

Вж. също



$_SESSION> <$_FILES
[edit] Last updated: Fri, 18 Sep 2009
 
add a note add a note User Contributed Notes $_REQUEST
rm at km-it dot de 24-Jan-2012 12:46
Note that the default distribution php.ini files does not contain the 'C' for cookies, due to security concerns.
See http://http://php.net/manual/en/ini.core.php#ini.request-order
mike o. 12-Mar-2010 01:31
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.
John Galt 07-Dec-2009 02:36
I wrote a function because I found it inconvenient if I needed to change a particular parameter (get) while preserving the others. For example, I want to make a hyperlink on a web page with the URL http://www.example.com/script.php?id=1&blah=blah+blah&page=1 and change the value of "page" to 2 without getting rid of the other parameters.

<?php
 
function add_or_change_parameter($parameter, $value)
 {
 
$params = array();
 
$output = "?";
 
$firstRun = true;
  foreach(
$_GET as $key=>$val)
  {
   if(
$key != $parameter)
   {
    if(!
$firstRun)
    {
    
$output .= "&";
    }
    else
    {
    
$firstRun = false;
    }
   
$output .= $key."=".urlencode($val);
   }
  }
  if(!
$firstRun)
  
$output .= "&";
 
$output .= $parameter."=".urlencode($value);
  return
htmlentities($output);
 }
?>

Now, I can add a hyperlink to the page (http://www.example.com/script.php?id=1&blah=blah+blah&page=1) like this:
<a href="<?php echo add_or_change_parameter("page", "2"); ?>">Click to go to page 2</a>

The above code will output
<a href="?id=1&amp;blah=blah+blah&amp;page=2">Click to go to page 2</a>

Also, if I was setting "page" to a string rather than just "2", the value would be urlencode()'d.
<a href="<?php echo add_or_change_parameter("page", "banana+split!"); ?>">Click to go to page banana split!</a>
would become
<a href="?id=1&amp;blah=blah+blah&amp;page=banana+split%21">Click to go to page banana split!</a>

[EDIT BY danbrown AT php DOT net: Contains a bugfix provided by (theogony AT gmail DOT com), which adds missing `echo` instructions to the HREF tags.]
smjg at iname dot com 13-Aug-2009 12:56
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.
strata_ranger at hotmail dot com 17-Jul-2008 05: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:
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites