Home > php教程 > php手册 > body text

PHP安全常识之验证数据

WBOY
Release: 2016-06-13 11:06:02
Original
1045 people have browsed it

在学习您的用户可能十分优秀,并且大多数用户可能完全按照期望来使用应用程序。但是,只要提供了输入的机会,也就极有可能存在非常糟糕的输入。作为一名应用程序开发人员,您必须阻止应用程序接受错误的输入。仔细考虑用户输入的位置及正确值将使您可以构建一个健壮、安全的应用程序。

下面列出了适用于各种验证数据的一般验证提示:

使用白名单中的值

始终重新验证有限的选项

使用内置转义函数

验证正确的数据类型(如数字)

白名单中的值(White-listed value)是正确的值,与无效的黑名单值(Black-listed value)相对。两者之间的区别是,通常在进行验证数据时,可能值的列表或范围小于无效值的列表或范围,其中许多值可能是未知值或意外值。

在保证PHP安全而进行验证数据时,记住设计并验证应用程序允许使用的值通常比防止所有未知值更容易。例如,要把字段值限定为所有数字,需要编写一个确保输入全都是数字的例程。不要编写用于搜索非数字值并在找到非数字值时标记为无效的例程。


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 Recommendations
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!