Linux 拨号vps windows公众号手机端

tp5如何防止sql注入

lewis 7年前 (2018-11-26) 阅读数 14 #VPS/云服务器
文章标签 sql注入tp5

tp5防止sql注入的方法:

1.在application/config.php中设置全局的过滤规则,如:

// 默认全局过滤方法 用逗号分隔多个

'default_filter' => 'htmlspecialchars,addslashes,strip_tags',

2.在获取变量的时候添加过滤方法,例如:

Request::instance()->get('name','','htmlspecialchars'); // 获取get变量 并用htmlspecialchars函数过滤Request::instance()->param('username','','strip_tags'); // 获取param变量 并用strip_tags函数过滤Request::instance()->post('name','','org\Filter::safeHtml'); // 获取post变量 并用org\Filter类的safeHtml方法过滤

3.支持传入多个过滤规则,例如:

Request::instance()->param('username','','strip_tags,strtolower'); // 获取param变量 并依次调用strip_tags、strtolower函数过滤

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门