$_REQUEST数组是PHP中比较常用的数组,一般从其中取出POST,GET,COOKIE等参数,在这里写明一下$_REQUEST数组的填充方式,防止出现一些意想不到的问题。
在php.ini中有如下的配置:
; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"
request_order这个配置项说明哪些全局变量(G,P,C,E,S分别代表$_GET,$_POST,$COOKIE,$_ENV,$_SERVER)的内容会被添加到$_REQUEST数组中,并且会指明变量填充的顺序,如果重名,那么后面填充的变量会覆盖前面填充的变量内容。如果把request_order置空,那么PHP将会使用variables_order(如下)配置项所指定的全局变量注册顺序来填充$_REQUEST数组,而不是说把$_REQUEST置空。
; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"
variables_order这个配置项用来指定全局变量EGPCS (Environment, Get, Post, Cookie, and Server)的解析顺序。如果variables_order被设置为SP,那么PHP会创建$_SERVER和$_POST,而不会创建$_ENV,$_GET,$_COOKIE等变量,如果被设置为”",那么PHP不会创建任何超级全局变量。
注意:有时候从$_REQUEST中取出的值不是想要的,考虑这样一个场景,如果在php.ini中设置request_order = “GPCES”,在HTTP请求中GET或者POST参数的name恰好与COOKIE的name相同,假如为foo,那么在程序逻辑中想通过$_REQUEST['foo']来获取到值是名为foo的一个cookie的值,而不是GET或者POST请求的值,所以$_REQUEST尽量不用,应该从$_GET,$_POST,$COOKIE,$_ENV,$_SERVER等变量中取出需要的值。
相关推荐
$_SERVER['HTTP_HOST']; localhost:80 $_SERVER['SERVER_NAME'] — ...$_SERVER['REQUEST_URI'];--这里是i而不是L /w/z/test.php?action=du&id=9 返回URL,也就是除域名外后面的完整的url地址路径,当然包含斜杠/。
1. $_REQUEST php中$_REQUEST可以获取以POST方法和GET方法提交的数据,但是速度比较慢 2. $_GET 用来获取由浏览器通过GET方法提交的数据。GET方法他是通过把参数数据加在提交表单的action属性所指的URL中,值和表单...
问题说起$_REQUEST,大家都知道的是它是$_GET和$_POST的集合。但是如果你有心的话,查一下文档,会看到: $_REQUEST An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. ...
咱们这次就来聊聊$GLOBALS&$_SERVER&$_REQUEST这三个超级全局变量。首先是$GLOBALS,它是PHP的一个超级全局变量组,在一个PHP脚本的全部作用域中都可以访问,它还是PHP的一个超级全局变量组,在一个PHP脚本的全部...
为’test’ 因此可以这样处理 复制代码 代码如下: foreach(array(‘_COOKIE’, ‘_POST’, ‘_GET’) as $_request) { foreach($$_request as $_key => $_value) { $_key{0} != ‘_’ && $$_key = addslashes($_...
$_SERVER[‘REMOTE_HOST’] //当前用户主机名 $_SERVER[‘REQUEST_URI’] //URL$_SERVER[‘REMOTE_PORT’] //端口。 $_SERVER[‘SERVER_NAME’] //服务器主机的名称。 $_SERVER[‘PHP_SELF’]//正在执行脚本的...
简单的说time()与$_SERVER[“REQUEST_TIME”]都是获得时间的,但time返回当前的 Unix 时间戳而$_SERVER[“REQUEST_TIME”]得到请求开始时的时间戳,稍有区别。 1. time() 获取当前的系统时间戳 int time(void) : ...
代码审核,是对应用程序源代码进行...$_REQUEST $_FILES $_ENV $_HTTP_COOKIE_VARS $_HTTP_ENV_VARS $_HTTP_GET_VARS $_HTTP_POST_FILES $_HTTP_POST_VARS $_HTTP_SERVER_VARS 我们应该对这些输入变量进行检查
3、$_SERVER[‘REQUEST_TIME’] — 请求开始时的时间戳。从 PHP 5.1.0 起有效。和time函数效果一样。 4、$_SERVER[‘argv’] — 传递给该脚本的参数。我试了下,get方法可以得到$_SERVER[‘argv’][0];post方法无法...
if (‘PUT’ == $_SERVER[‘REQUEST_METHOD’]) { parse_str(file_get_contents(‘php://input’), $_PUT); } 通过php://input得到的数据是raw data,所以需要用parse_str解析一下。 不过需要说明的是,当...
$d3PayOrderId = $_REQUEST[ d3PayOrderId ] //第三方支付大师返回的订单号 $orderId = $_REQUEST[ orderId ] //商户订单号 $realMoney = $_REQUEST[ realMoney ] //支付金额 $payStatus = $_REQUEST[ payStatus...
php // 说明:获取 _SERVER[‘REQUEST_URI’] 值的通用解决方案 function request_uri() { if (isset($_SERVER[‘REQUEST_URI’])) { $uri = $_SERVER[‘REQUEST_URI’]; } else { if (isset($_SERVER[‘argv’])) {...
$version = $_REQUEST['version']; //版本号 $merId = $_REQUEST['merId']; //商户ID $payMoney =$_REQUEST['payMoney']; //支付金额 $orderId = $_REQUEST['orderId']; //订单号 $payResult = $_REQUEST['payResult...
$paginator->setUrlTemplate(array('name'=>@$_REQUEST['name'], 'age'=>@$_REQUEST['age'], 'pageNo' => '{no}')) ->setStringTemplate("{first} {previous} {list} {next} {last}") ->setItemConfig(array('list...
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ...
如果是//www.jb51.net/p1141.html形式的URL,可通过$_SERVER[‘REQUEST_URI’]和$_SERVER[‘QUERY_STRING’]值的区别来分析,最主要是如果页面是通过重定向会产生$_SERVER[‘REDIRECT_QUERY_STRING’]和$_SERVER[...
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) $errorCorrectionLevel = $_REQUEST['level']; $matrixPointSize = 4; if (isset($_REQUEST['size'])) $...
$this->code = isset($_REQUEST['code'])? $_REQUEST['code'] : ''; $this->state = isset($_REQUEST['state'])? $_REQUEST['state'] : ''; $this->app_id = $app_id; $this->app_key = $...