


Usage analysis of PHP function import_request_variables(), importrequest_PHP tutorial
Usage analysis of PHP function import_request_variables(), importrequest
This article analyzes the usage of PHP function import_request_variables() with examples. Share it with everyone for your reference, the details are as follows:
The import_request_variables function can import GET/POST/Cookie variables into the global scope when register_global = off.
Description
bool import_request_variables ( string types [, string prefix])
Import GET/POST/Cookie variables into the global scope. This function is useful if you have disabled register_globals but still want to use some global variables.
You can use the types parameter to specify the variables that need to be imported. The letters 'G', 'P' and 'C' can be used to represent GET, POST and Cookie respectively. These letters are not case-sensitive, so you can use any combination of 'g', 'p' and 'c'. POST contains file information uploaded through the POST method. Note the order of these letters, when using "gp" the POST variable will overwrite the GET variable with the same name. Any letters outside of GPC will be ignored.
Theprefix parameter serves as the prefix of the variable name and is placed before all variables imported into the global scope. So if you have a GET variable named "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 specify an empty string as a prefix, you will get an E_NOTICE level error. Note level errors are not displayed using the default error reporting level.
<?php // This will import GET and POST vars // with an "rvar_" prefix import_request_variables("gp", "rvar_"); echo $rvar_foo; ?>
Use the import_request_variables() function to selectively register a collection of global variables. You can use this function to import the values of $_GET, $_POST, and $_COOKIE. You can also add a prefix to each imported variable.
The type string in the parameter allows g, p, c characters, or any combination of the three characters. Among them, "g" represents the GET variable, "p" represents the POST variable, and "c" represents cookies. Note: There is a difference in the order of the 3 characters. When "pg" is used, the POST variable will overwrite the $_GET variable with the same name; conversely, when "gp" is used, the $_GET variable array will take precedence over $_POST. .
A script example using the import_request_variable() function to implement variable import is as follows:
//导入POST提交的变量值,前缀为post_ import_request_variable("p", "post_"); //导入GET和POST提交的变量值,前缀为gp_,GET优先于POST import_request_variable("gp", "gp_"); //导入Cookie和GET的变量值,Cookie变量值优先于GET import_request_variable("cg", "cg_");
If we use the "pg parameter" in the import_request_variables() function, please see the following script example:
<?php if(isset($_REQUEST['btn_submit'])){ echo "正常取得的表单POST变量值:".$_REQUEST['Username']."<br />"; import_request_variables("pg", "import_"); //显示导入的变量名称 echo "使用import_request_variables函数导入的变量值:".$import_Username; } ?> <form id="test_form" name="test_form" method="POST" action=""> 请输入您的名字: <label> <input type="text" name="Username" id="Username" /> </label> <label> <input type="submit" name="btn_submit" id="btn_submit" value="提交" /> </label> <br /> </form>
The form prompts the user to enter a name. Once completed and submitted, the script will display the submitted name in the browser.
Note: The prefix parameter is required. If no prefix is specified, or an empty string is specified as the variable prefix, PHP will throw an E_NOTICE error.
The import_request_variables() function provides us with an intermediate method, which is suitable for the following situations:
1. When the user cannot use the super variable array;
2. When the register_globals parameter in the php.ini configuration file is Off (the default value for versions after PHP 5 is Off), use import_request_variables to import the GET/POST/Cookie super variable arrays into the global scope.
3. During development, as long as the introduced variable scope is declared, there is no need to write a bunch of long super global array names in $_GET or $_REQUEST.
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", "Introduction to PHP basic syntax", "php operation office documentation" Summary of skills (including word, excel, access, ppt)", "Summary of php date and time usage", "Introduction to php object-oriented programming tutorial", "Summary of php string (string) usage", "Introduction to php mysql database operation" Tutorial" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- PHP array function array_multisort() usage example analysis
- PHP method of calculating the sum and product of values in an array (array_sum and array_product functions )
- A large summary of PHP mathematical operation functions (classics worth collecting)
- Detailed explanation of PHP anonymous functions and precautions
- Summary of common PHP array function usage
- PHP Usage examples of anonymous functions and use clauses
- Briefly talk about the strlen function in PHP
- Analysis of the source code of array_keys and array_unique functions in PHP
- PHP queries and deletes duplicates of multiple columns in the database Data method (implemented using array functions)
- php’s powerful time conversion function strtotime
- PHP function timeout processing method
- A preliminary study on PHP’s closure (Closure) anonymous function

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools