In php Tutorial 5.2, the built-in filter module is used for variable verification and filtering.
For more information about how to filter variables, see what I previously mentioned. Here we will look at how to filter user input directly.
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
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 types of user input:
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
With various built-in verification tokens, you can solve similar user input filtering and other "physical activity" problems ".
Finally, we need to mention the small trap of filter.
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 a lot of time.
If the data provided by users such as $ _ get and $ _ post are improperly used, such as incomplete verification and filtering, security problems may occur. In general, we will write a regular expression to verify whether the data format is legal.