PHP anti-XSS anti-SQL injection code

Source: Internet
Author: User

Here is a function to filter what the user has entered! You can call this function to filter by using post to pass the value!

    /**     *  Filter Parameter      * @ param string  $str   Accepted parameters      *  @return  string      */    static public function filterwords ($STR)      {         $farr  = array (                  "/< (\\/?) (script|i?frame|style|html|body|title|link|meta|object|\\?| \\%) ([^>]*?) >/isu ",                "/( <[^>]*) on[a-za-z]+\s*= ([^>]*>)/isu ",                  "/select|insert|update|delete|\ ' |\/\*|\*|\.\.\/|\.\/|union|into|load_file| Outfile|dump/is "        )          $str  = preg_replace ($farr, ", $str);         return  $str;     }        /* *     *  filter the accepted parameters or arrays, such as $_get,$_post     *  @param  array|string  $arr   accepted parameters or arrays      *  @return  array|string      */    static public function filterarr ($arr)     {        if (Is_array ($arr)) {             foreach ($arr  as  $k  =>  $v) {                  $arr [$k] =  self::filterwords ($v);            }         }else{             $arr  = self:: Filterwords ($v);        }         return  $arr;     }


PHP anti-XSS anti-SQL injection code

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.