Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to receive external parameters in PHP

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the ways to receive external parameters in PHP". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn together "what are the ways to receive external parameters in PHP"!

For a web language like PHP, taking arguments is a very important ability. After all, the data passed up from the front-end form or asynchronous request must be retrieved in order to perform normal interactive presentation. Of course, this is also a must-have capability for all languages capable of web development. Today we're going to take a look at PHP's various forms of connection.

First, we need to prepare a static page, like this one, which provides a form with a GET parameter in the url:

Document

Name:

Telephone:

Address (province):

Address (City):

Interest 1:

Interest 2:

Interest 3:

Education 1:

Education 2:

Normal\$_GET,$_POST methods//Normal GET, POST

echo $_GET['show'], ''; // 1

echo $_POST ['name '],''; //content submitted

This is the most basic and direct way to access parameters, GET parameters are obtained through $_GET, POST parameters are obtained through $_POST, and they do not interfere with each other.

Normal $_REQUEST mode //Use Request

echo $_REQUEST['show'], ''; // 1

echo $_REQUEST ['tel '],''; //content submitted

$_REQUEST gets all the parameters in the request, excluding uploading files. That is, it contains everything in the $_GET,$_POST, and $_COOKIE arguments (configuration required, not included by default). One thing to note here is that after PHP5.3, the parameter variable content accepted by $_REQUEST is specified by request_order in php.ini file. By default, the value of this configuration parameter is GP, that is, GET and POST, and there is no COOKIE. If you want COOKIE, you need to modify it by adding a C here.

What if $_GET,$_POST contain something with the same name? REQUEST display order is also based on the order of the configuration parameters, from left to right, the latter cover the front, such as you configure GP then the order of parameter coverage is: POST > GET, the final display is the content of POST.

register_globals problem // register_globals if open

echo $name, ''; //content submitted

echo $tel, ''; //content submitted

This is an insecure configuration and is configured in the php.ini file. Its role is to request the parameters directly into variables, there are global variable pollution problems, do not open!!! The php.ini file is now basically closed by default.

import_request_variables // import_request_variables Sorry, it has been cancelled since 5.4

import_request_variables('pg', 'pg_');

echo $pg_show, '';

echo $pg_name, '';

This function manually registers the contents of the specified parameter variable as a global variable. Similarly, it was cancelled after 5.4. Such a function will have risks. We know that there was such a function.

extract extract($_POST, EXTR_PREFIX_ALL, 'ex');

echo $ex_name, ''; //content submitted

echo $ex_tel, ''; //content submitted

Extract is the currently supported alternative to the above two parameter transitions. It is by ourselves to control the coverage of existing variables, that is, the second parameter, so that in a controlled environment can greatly avoid the problem of polluting global variables, of course, the premise is that we have to determine the use of it, the specific content can be found by ourselves.

The. in the parameter name and spaces //parameter name. and spaces

echo $_REQUEST ['address_prov'],''; //content submitted

echo $_REQUEST ['address_city'],''; //content submitted

If the name of the input submitted by the form contains. Or spaces, will be converted directly to underscores. However, we do not recommend using it in front-end naming. Or spaces, need to use underscore directly on the good, before and after do not cause ambiguity.

[] in parameter name //[] in parameter name

print_r($_REQUEST['interest']); // Array (v,....)

echo '';

print_r($_REQUEST['edu']); // Array (k/v,....)

When the name of the input submitted by the form is in array form, i.e."interest[]" or "edu[one]", the parameters we receive will be in array form by default.

php://input // php://input

$content = file_get_contents('php://input');

print_r($content); //name=xxx&.....

Finally, there is the php://input form that is often used in interface development. Generally, because there are many safety or parameter fields, the front end rides through the form of Body Raw and directly passes a whole section of Body content. At this time, it can only be obtained in this form. The original content of this Body Raw will generally be a whole paragraph of text, or it may be some encrypted content. The format can be defined by yourself. For normal forms, we will receive the original form content, like name=xxx&tel=xxx&... such content.

Note that enctype="multipart/form-data" is not available. At the same time, this way is also to replace the $HTTP_RAW_POST_DATA global variable, do not use the elimination ability oh, update the new version of PHP as soon as possible to use the new syntax features oh!

Thank you for reading, the above is "PHP receive external parameters in what way" content, after learning this article, I believe we receive external parameters in PHP what way this problem has a deeper understanding, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report