PHP to determine if there are instances of malicious characters _php Tutorial

Source: Internet
Author: User
Using PHP to filter the principle of malicious characters is very simple we just define the characters and then use the foreach traversal of the malicious word repertoires, using Strpost to detect whether the user submitted data in the malicious word repertoires characters can be instantiated.

Example 1, determining whether a character exists

The code is as follows Copy Code

function Is_bad_chars ($STR) {
$bad _chars = Array ("\", "'" ' "'", ' "', '/', ' * ', ', '), ' < ', ' > ', ' r '," T "," N ", ' $ ', ' (', ') ', '% ', ' + ', '? ', '; ', ' ^ ', ' # ', ': ', ', ', ', ' = ', ' | ', '-');
foreach ($bad _chars as $value) {
if (Strpos ($str, $value)!== false) {
return true;
}
}
}

According to the above example we can do a filter keyword instance

The code is as follows Copy Code

function Outip ($IP) {//Exclude IP
@ $txt = file_get_contents ("Ip/ip.txt");
$txtarr = Explode ("rn", Trim ($txt));
if (count ($txtarr) <0) {
return false;
}
if (In_array ($ip, $txtarr)) {
return true;
}else{
return false;
}
}

Ip.txt file is to put some words you want to filter, which is each word or word for a line

http://www.bkjia.com/PHPjc/632830.html www.bkjia.com true http://www.bkjia.com/PHPjc/632830.html techarticle using PHP to filter the principle of malicious characters is very simple, we just define the characters and then use the foreach traversal of the malicious word repertoires, using Strpost to detect whether the user submitted data in the malicious word repertoires ...

  • 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.