Usage analysis of filter_input function in php, phpfilter_input
This article analyzes the usage of filter_input function in PHP with examples. Share it with everyone for your reference. The specific analysis is as follows:
In php5.2, there is a built-in filter module, which is used for variable verification and filtering, filtering variables and other operations. Here we look at how to directly filter user input.
The filter_input function corresponding to the filter module is very simple to use. For example, if we filter the get parameter named sample input by the user to be an integer, then we can write it like this:
Copy code The code is as follows:
filter_input(input_get, "sample", filter_sanitize_number_int);
The parameters of filter_input are user input type, corresponding input name, and filtering (verification) constants. Currently, filter_input supports the following types of user input:
Copy code The code is as follows:
input_get // Corresponds to $_get
input_post // Corresponds to $_post
input_cookie // Corresponds to $_cookie
input_server // Corresponds to $_server
input_env // Corresponds to $_env
With the various built-in verification tags provided, you can solve similar "physical tasks" such as user input filtering. Finally, we still need to mention the traps of filter.
Copy code The code is as follows:
filter_var('abc', filter_validate_boolean); // bool(false)
filter_var('0', filter_validate_boolean); // bool(false)
The filter module is mentioned again on php arch. Indeed, this module can save us a lot of time. Here we will organize it again. If the data provided by users such as $_get and $_post are used improperly, such as incomplete verification and filtering, it can easily cause problems. Security issues, usually, we will write "a bunch of" regular expressions to verify whether the data format is legal.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/912278.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912278.htmlTechArticleAnalysis of the usage of filter_input function in php, phpfilter_input This article analyzes the usage of filter_input function in php. Share it with everyone for your reference. The specific analysis is as follows: In php5.2, within...