Usage analysis of filter_input function in php, phpfilter_input_PHP tutorial

WBOY
Release: 2016-07-13 10:14:02
Original
1233 people have browsed it

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.

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!