find($_GET["id"]); 即便用户输入了一些恶意的id参数,系统也会自"/> find($_GET["id"]); 即便用户输入了一些恶意的id参数,系统也会自">

Heim >Backend-Entwicklung >PHP-Tutorial >ThinkPHP 防止SQL注入

ThinkPHP 防止SQL注入

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 14:24:591251Durchsuche

 对于WEB应用来说,SQL注入攻击无疑是首要防范的安全问题,系统底层对于数据安全方面本身进行了很多的处理和相应的防范机制,例如:

$User = M("User"); // 实例化User对象
$User->find($_GET["id"]);

即便用户输入了一些恶意的id参数,系统也会自动加上引号避免恶意注入。事实上,ThinkPHP对所有的数据库CURD的数据都会进行escape_string处理。

通常的安全隐患在于你的查询条件使用了字符串参数,然后其中一些变量又依赖由客户端的用户输入,要有效的防止SQL注入问题,我们建议:

查询条件尽量使用数组方式,这是更为安全的方式;

开启数据字段类型验证,可以对数值数据类型做强制转换;

使用自动验证和自动完成机制进行针对应用的自定义过滤;

字段类型检查、自动验证和自动完成机制我们在模型部分已经有详细的描述。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn