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
$_REQUEST — HTTP リクエスト変数
変更履歴
| バージョン | 説明 |
|---|---|
| 5.3.0 | request_order が導入されました。 このディレクティブは $_REQUEST の内容に影響を及ぼします。 |
| 4.3.0 | $_FILES の情報が $_REQUEST から削除されました。 |
| 4.1.0 | $_REQUEST が導入されました。 |
注意
注意: これは 'スーパーグローバル' あるいは自動グローバル変数と呼ばれるものです。 スクリプト全体を通してすべてのスコープで使用することができます。 関数やメソッドの内部で使用する場合にも global $variable; とする必要はありません。
注意: コマンドライン で実行する場合、ここには argv や argc の内容は含まれません。これらの内容は $_SERVER 配列に格納されます。
注意: 変数の内容は、GET や POST そして COOKIE といった仕組みで入力されます。 これらは信頼できるとは限りません。この配列内に含まれる変数の値や順序は、 PHP の設定ディレクティブ variables_order で決まります。
$_REQUEST
strata_ranger at hotmail dot com
17-Jul-2008 05:04
17-Jul-2008 05:04
not at telling dot org
22-May-2008 04:05
22-May-2008 04: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 )
