PHP anti-XSS anti-SQL injection code

Source: Internet
Author: User
Tags how to prevent sql injection

As a developer always remember a word, never trust any user input! Many times our site will be due to our developers to write the code is not rigorous, and make the site under attack, causing unnecessary loss! Here's how to prevent SQL injection!

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 Parameters *     @param string $str parameters accepted     * @return String *    /static public function Filterwords ($STR) c6/>{        $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 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.