search
Homephp教程php手册php中filter_input函数用法分析,phpfilter_input

php中filter_input函数用法分析,phpfilter_input

本文实例分析了php中filter_input函数用法。分享给大家供大家参考。具体分析如下:

在 php5.2 中,内置了filter 模块,用于变量的验证和过滤,过滤变量等操作,这里我们看下如何直接过滤用户输入的内容.

fliter 模块对应的 filter_input 函数使用起来非常的简单,例如我们过滤用户输入名为 sample 的 get 参数为整型,那么可以这样写:

复制代码 代码如下:

filter_input(input_get, "sample", filter_sanitize_number_int);

filter_input 的参数分别是用户输入类型、对应的输入名称、以及过滤(验证)常量,目前 filter_input 支持下面几种用户输入:

复制代码 代码如下:

input_get // 对应 $_get
input_post // 对应 $_post
input_cookie // 对应 $_cookie
input_server // 对应 $_server
input_env // 对应 $_env


配合内置提供的各种验证标记符,就可以解决类似的用户输入过滤等“体力活”,最后,还是需要再提下 filter 的个不大不小的陷阱.

复制代码 代码如下:

filter_var('abc', filter_validate_boolean); // bool(false)
filter_var('0',   filter_validate_boolean); // bool(false)


php arch 上重新提及 fliter 模块,的确这个模块能节省我们不少的时间,这里再次整理下,$_get 和 $_post 等用户提供的数据如果使用不当,如验证、过滤不全面,就很容易造成安全问题,通常情况下,我们会编写“一坨”正则来验证数据格式是否合法.

希望本文所述对大家的PHP程序设计有所帮助。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software