1、 实际过滤函数 可适当修改其中的正则表示式

PHP POST, GET 参数过滤,预防sql注入函数
 1 static public function filterWords(&$str)
 2     {
 3         $farr = array(
 4             "/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
 5             "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
 6             "/select\b|insert\b|update\b|delete\b|drop\b|;|\"|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|dump/is"
 7         );
 8         $str = preg_replace($farr,'',$str);
 9         $str = strip_tags($str);
10         return $str;
11     }
PHP POST, GET 参数过滤,预防sql注入函数

2、调用此函数 过滤参数中的value值

PHP POST, GET 参数过滤,预防sql注入函数
static function filterParams(&$params, $tmp = array())
    {
        if(is_array($params)){
            foreach($params as $k => &$v){
                if(is_array($v))
                {
                    self::filterParams($v);
                }else{
                    self::filterWords($v);

                }
            }
        }
        else
        {
            $arr[] = self::filterWords($params);
        }
        return $params;
    }
PHP POST, GET 参数过滤,预防sql注入函数

3、调用此函数,过滤参数中的key值

PHP POST, GET 参数过滤,预防sql注入函数
 1 static  function filterKeys($arr, $subKey, &$myArr)
 2     {
 3         foreach($arr as $k=>$v)
 4         {
 5             if(is_array($v))
 6             {
 7                 $filterKey = self::filterWords($k);
 8                 self::filterKeys($v, $filterKey, $myArr);
 9 
10             }else{
11                 $filterKey = self::filterWords($k);
12                 if($subKey != '')
13                 {
14                     $myArr[$subKey][$filterKey] = $v;
15                 }else{
16                     $myArr[$filterKey] = $v;
17                 }
18             }
19         }
20 
21     }
PHP POST, GET 参数过滤,预防sql注入函数

转自 https://www.cnblogs.com/zakun/p/5603522.html

 

1、 实际过滤函数 可适当修改其中的正则表示式

PHP POST, GET 参数过滤,预防sql注入函数
 1 static public function filterWords(&$str)
 2     {
 3         $farr = array(
 4             "/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
 5             "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
 6             "/select\b|insert\b|update\b|delete\b|drop\b|;|\"|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|dump/is"
 7         );
 8         $str = preg_replace($farr,'',$str);
 9         $str = strip_tags($str);
10         return $str;
11     }
PHP POST, GET 参数过滤,预防sql注入函数

2、调用此函数 过滤参数中的value值

PHP POST, GET 参数过滤,预防sql注入函数
static function filterParams(&$params, $tmp = array())
    {
        if(is_array($params)){
            foreach($params as $k => &$v){
                if(is_array($v))
                {
                    self::filterParams($v);
                }else{
                    self::filterWords($v);

                }
            }
        }
        else
        {
            $arr[] = self::filterWords($params);
        }
        return $params;
    }
PHP POST, GET 参数过滤,预防sql注入函数

3、调用此函数,过滤参数中的key值

PHP POST, GET 参数过滤,预防sql注入函数
 1 static  function filterKeys($arr, $subKey, &$myArr)
 2     {
 3         foreach($arr as $k=>$v)
 4         {
 5             if(is_array($v))
 6             {
 7                 $filterKey = self::filterWords($k);
 8                 self::filterKeys($v, $filterKey, $myArr);
 9 
10             }else{
11                 $filterKey = self::filterWords($k);
12                 if($subKey != '')
13                 {
14                     $myArr[$subKey][$filterKey] = $v;
15                 }else{
16                     $myArr[$filterKey] = $v;
17                 }
18             }
19         }
20 
21     }
PHP POST, GET 参数过滤,预防sql注入函数

转自 https://www.cnblogs.com/zakun/p/5603522.html

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2021-10-24
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-07-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案