PHP tips--Global var的另钟解决方法

王朝php·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

很多初学者不知道怎么处理register_globals = off情况下变量,后来学会了又嫌 _GET _POST等全局数组麻烦 那么试试如下函数

// This will import GET and POST vars

// with an "rvar_" prefix

import_request_variables("gP", "rvar_");

print $rvar_foo;

import_request_variables

(PHP 4 >= 4.1.0)

import_request_variables -- Import GET/POST/Cookie variables into the global scope

Descriptionbool import_request_variables ( string types [, string prefix])

Imports GET/POST/Cookie variables into the global scope. It is useful if you disabled register_globals, but would like to see some variables in the global scope.

Using the types parameter, you can specify which request variables to import. You can use 'G', 'P' and 'C' characters respectively for GET, POST and Cookie. These characters are not case sensitive, so you can also use any combination of 'g', 'p' and 'c'. POST includes the POST uploaded file information. Note that the order of the letters matters, as when using "gp", the POST variables will overwrite GET variables with the same name. Any other letters than GPC are discarded.

The prefix parameter is used as a variable name prefix, prepended before all variable's name imported into the global scope. So if you have a GET value named "userid", and provide a prefix "pref_", then you'll get a global variable named $pref_userid.

If you're interested in importing other variables into the global scope, such as SERVER, consider using extract().

注: Although the prefix parameter is optional, you will get an E_NOTICE level error if you specify no prefix, or specify an empty string as a prefix. This is a possible security hazard. Notice level errors are not displayed using the default error reporting level.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航