Simple PHP anti-injection content filtering Method _php Tutorial

Source: Internet
Author: User
Content filtering is to prevent some security injection or cross-domain operation, let's take a look at some of my simple anti-injection content filtering program code, I hope the article will help you classmates.

Method One, filter out some useless content

Filter useless information is more rigorous, useful may also input not to go in, you can find other filtering methods on the Internet:

The code is as follows Copy Code

function checkhtml ($data) {
$ret = Preg_match ("/[".,:; *?~ '!@#$%^&+=) (<>{}]|]| [|/|\|"|| /", $data);
if ($ret = = 1) {
return false; Exit
} else {
return true;
}
}

Example 2 Filter Some HTML tags

The code is as follows Copy Code


Function uh ($STR)
{
$farr = Array (
"/s+/",//filter Extra blanks
"/< (/?) (scripti?framestylehtmlbodytitlelinkmeta?%) ([^>]*?) >/isu ",//filter";
echo "Back";
Exit
}
}
echo "What you have entered is:". $str;
}
?>

Test whether the filter takes effect:


http://www.bkjia.com/PHPjc/632820.html www.bkjia.com true http://www.bkjia.com/PHPjc/632820.html techarticle content filtering is to prevent some security injection or cross-domain operation, let's take a look at my collation of a few simple anti-injection content filtering program code, I hope the article on the ...

  • Related Article

    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.