Php filter_input function Usage Analysis, phpfilter_input
This article analyzes the usage of the filter_input function in php. Share it with you for your reference. The specific analysis is as follows:
In php5.2, the built-in filter module is used to verify and filter variables. Here we will look at how to directly filter user input content.
The filter_input function corresponding to the fliter module is very simple to use. For example, if we filter the get parameter named sample as an integer, we can write it like this:
Copy codeThe Code is as follows: filter_input (input_get, "sample", filter_sanitize_number_int );
Filter_input parameters are user input types, corresponding Input names, and filtering (verification) constants. Currently, filter_input supports the following user input:
Copy codeThe Code is as follows: input_get // corresponding to $ _ get
Input_post // corresponding to $ _ post
Input_cookie // corresponding to $ _ cookie
Input_server // corresponding to $ _ server
Input_env // corresponding to $ _ env
In combination with the various built-in verification tokens, it can solve similar user input filtering and other "Physical Activity". Finally, we still need to mention a small trap of filter.
Copy codeThe Code is as follows: filter_var ('abc', filter_validate_boolean); // bool (false)
Filter_var ('0', filter_validate_boolean); // bool (false)
The fliter module is mentioned again on php arch, which can save us a lot of time. Here, we will sort out the data provided by users such as $ _ get and $ _ post. If they are not properly used, if verification and filtering are incomplete, security problems are easily caused. Generally, we write a "one batch" Regular Expression to verify whether the data format is legal.
I hope this article will help you with PHP programming.