php sql语句过滤,php如何做sql过滤

20d0c65f0f500a876d48c23e52e1519f.png

php如何做sql过滤

SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据,致使非法数据侵入系统。因此,在执行sql语句前,一定要对用户输入的数据进行过滤处理。

防止sql注入的函数,过滤掉那些非法的字符,提高sql安全性,同时也可以过滤XSS的攻击。function filter($str)

{

if (empty($str)) return false;

$str = htmlspecialchars($str);

$str = str_replace( '/', "", $str);

$str = str_replace( '"', "", $str);

$str = str_replace( '(', "", $str);

$str = str_replace( ')', "", $str);

$str = str_replace( 'CR', "", $str);

$str = str_replace( 'ASCII', "", $str);

$str = str_replace( 'ASCII 0x0d', "", $str);

$str = str_replace( 'LF', "", $str);

$str = str_replace( 'ASCII 0x0a', "", $str);

$str = str_replace( ',', "", $str);

$str = str_replace( '%', "", $str);

$str = str_replace( ';', "", $str);

$str = str_replace( 'eval', "", $str);

$str = str_replace( 'open', "", $str);

$str = str_replace( 'sysopen', "", $str);

$str = str_replace( 'system', "", $str);

$str = str_replace( '$', "", $str);

$str = str_replace( "'", "", $str);

$str = str_replace( "'", "", $str);

$str = str_replace( 'ASCII 0x08', "", $str);

$str = str_replace( '"', "", $str);

$str = str_replace( '"', "", $str);

$str = str_replace("", "", $str);

$str = str_replace("&gt", "", $str);

$str = str_replace("&lt", "", $str);

$str = str_replace("

$str = str_replace("", "", $str);

$str = str_replace("

$str = str_replace("", "", $str);

$str = str_replace("select","",$str);

$str = str_replace("join","",$str);

$str = str_replace("union","",$str);

$str = str_replace("where","",$str);

$str = str_replace("insert","",$str);

$str = str_replace("delete","",$str);

$str = str_replace("update","",$str);

$str = str_replace("like","",$str);

$str = str_replace("drop","",$str);

$str = str_replace("DROP","",$str);

$str = str_replace("create","",$str);

$str = str_replace("modify","",$str);

$str = str_replace("rename","",$str);

$str = str_replace("alter","",$str);

$str = str_replace("cas","",$str);

$str = str_replace("&","",$str);

$str = str_replace(">","",$str);

$str = str_replace("

$str = str_replace(" ",chr(32),$str);

$str = str_replace(" ",chr(9),$str);

$str = str_replace(" ",chr(9),$str);

$str = str_replace("&",chr(34),$str);

$str = str_replace("'",chr(39),$str);

$str = str_replace("
",chr(13),$str);

$str = str_replace("''","'",$str);

$str = str_replace("css","'",$str);

$str = str_replace("CSS","'",$str);

$str = str_replace("

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值