php function Import_request_variables () usage analysis, importrequest_php tutorial

Source: Internet
Author: User

php function Import_request_variables () usage analysis, importrequest


This paper analyzes the usage of PHP function import_request_variables (). Share to everyone for your reference, as follows:

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 ']. "
"; Import_request_variables (" PG "," Import_ ");//Displays the imported variable name echo" variable value imported using the Import_request_variables function: ". $import _ Username;}? >

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.

More readers interested in PHP related content can view this site: "Summary of PHP operations and operator usage," PHP Network Programming Tips Summary, "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document tips summary (including word,excel,access, ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • PHP Array function array_multisort () Usage Example analysis
    • PHP computes the sum and product of values in an array (Array_sum and array_product functions)
    • PHP Math function Summary (classic worth collecting)
    • An explanation of PHP anonymous functions and precautions
    • Summary of common array function usage in PHP
    • PHP anonymous function and use clause usage instance
    • Simply talk about the strlen function in PHP
    • Analysis of source code of Array_keys and Array_unique functions in PHP
    • Php method for querying and deleting multiple columns of data in a database (using array functions)
    • PHP Powerful Time-conversion function strtotime
    • PHP function Timeout processing method
    • Probe into the anonymous function of PHP's closure (Closure)

http://www.bkjia.com/PHPjc/1117038.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117038.html techarticle php function import_request_variables () usage analysis, importrequest This article analyzes the PHP function Import_request_variables () usage. Share to everyone for your reference, as follows: Im ...

  • 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.