php function Import_request_variables () usage and example analysis

Source: Internet
Author: User
This article mainly introduces PHP function import_request_variables () usage, combined with instance form analysis function of import_request_variables function, definition and related use skill, need friend can refer to next

The Import_request_variables function can import the Get/post/cookie variable into the global scope at register_global = off.

Describe

BOOL Import_request_variables (String types [, string prefix])

Import the Get/post/cookie variable into the global scope. This function is useful if you prohibit register_globals, but want to use some global variables.

You can use the types parameter to specify which variables you want to import. You can use the letters ' G ', ' P ' and ' C ' to represent GET, POST, and Cookie, respectively. The letters are not case-sensitive, so you can use any combination of ' g ', ' P ' and ' C '. Post contains file information that is uploaded via the Post method. Note The order of these letters, and when "GP" is used, the POST variable overwrites the GET variable with the same name. Any non-GPC letters will be ignored.

The prefix parameter is prefixed to the variable name and placed before all variables that are imported into the global scope. So if you have a GET variable called "userid" and provide "pref_" as a prefix, you will get a global variable named $pref _userid.

If you are interested in importing other global variables, such as SERVER variables, consider using extract ().

Note: Although the prefix parameter is optional, if you do not specify a prefix, or you specify an empty string as the prefix, you will get an E_notice level error. Using the default error reporting level is an error that does not show the attention (Notice) level.

<?php//This would import GET and POST vars//with an "Rvar_" Prefiximport_request_variables ("GP", "Rvar_"); Echo $rvar _f oo;? >

Use the Import_request_variables () function to selectively register a collection of global variables. You can use this function to import values for $_get, $_post, and $_cookie, and you can add a prefix (prefix) for each imported variable.

The types string in the parameter allows for any combination of G, p, c characters, or 3 characters. Where "G" represents a Get variable, "P" represents a post variable and "C" denotes a cookie. Note: The order of 3 characters is different, when using "PG", the POST variable will overwrite the $_get variable with the same name, conversely, when using "GP", the $_get variable array will take precedence over $_post.

Examples of scripts that implement variable import using the Import_request_variable () function are as follows:

Import the variable value of post submission, prefixed with post_import_request_variable ("P", "Post_"),//import the value of the variable for Get and post commits, prefixed with gp_,get precedence over postimport_request _variable ("GP", "gp_");//import cookie and get variable value, cookie variable value takes precedence over getimport_request_variable ("CG", "cg_");

If we use the "PG parameter" in the Import_request_variables () function, consider the following script example:

<?phpif (Isset ($_request[' Btn_submit ')) {echo "normal get form Post variable value:". $_request[' Username ']. " <br/> "; Import_request_variables (" PG "," Import_ ");//display the imported variable name echo" variable value imported with Import_request_variables function: ". $ Import_username;}? ><form id= "Test_form" name= "Test_form" method= "POST" action= "" > Please enter your name: <label><input type= "Text" Name= "Username" id= "Username"/></label><label><input type= "Submit" Name= "Btn_submit" id= "Btn_ Submit "value=" Submission "/></label><br/></form>

The form prompts the user to enter a name, complete and submit, and the script will display the submitted name on the browser.

Note: The prefix prefix parameter is required, and PHP throws a e_notice error if no prefix is specified, or if an empty string is specified as the variable prefix.

The Import_request_variables () function provides us with an intermediate method for the following situations:

1. When the user cannot use the super variable array;
2. When the register_globals parameter of the php.ini configuration file is off (the version after PHP 5 is off by default), the Import_request_variables will be used to get/post/ A few super variable arrays of cookies are imported into the global scope.
3. At development time, you do not have to write $_get or $_request a bunch of long super global array names as long as you declare the range of variables introduced.

Summary: The above is the entire content of this article, I hope to be able to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.