Php filter_input function Usage Analysis, phpfilter_input

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.