PHP TIPS - Ether Solution for Global Var

xiaoxiao2021-03-06  70

Many beginners don't know how to deal with register_globals = OFF cases, and then learn to have suspected _GET _POST and other global arrays. Try to try the following functions // 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

Description

Bool 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 Intested In Importing Other Variables Into The Global Scope, Such As Server, Consider Using Extract ().

转载请注明原文地址:https://www.9cbs.com/read-121232.html

New Post(0)