PHP POST, GET parameter filtering, prevent SQL injection function

Source: Internet
Author: User

1, the actual filter function can be appropriately modified in which the regular expression

1 static public Function filterwords (& $str    {3         $farr = array(4             "/< (\\/?) (script|i?frame|style|html|body|title|link|meta|object|\\?| \\%) ([^>]*?) >/isu ", 5             "/(<[^>]*) on[a-za-z]+\s*= ([^>]*>)/isu ", 6                     ); 8         $str = Preg_replace ($ Farr, ", $str); 9         $str = strip_tags ($str); return $str;     

2. Call this function to filter the value values in the parameter

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; }

3. Call this function to filter the key value in the parameter

1 static  function FilterKeys ($arr, $subKey, & $myArr    {3         foreach ($arr as $k + = $v        {5<  C8/>if (Is_array ($v {7 $filterKey = self::filterwords ($k); 8 Self::filterkeys ($v, $filterKey, $myArr); 9 10 }else{One $filterKey = Self::filterwords ($k); if ($subKey! = " {$MYARR [$subKey] [$filterKey] = $v  ;}else{$MYARR [$filterKey] = $v }20}          

PHP POST, GET parameter filtering, prevent SQL injection function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.