SQL injection character detection function _php Tutorial

Source: Internet
Author: User
Write your own SQL injection detection function, you can effectively detect the user Post,get over the reference to filter, the need for a friend reference.
The code is as follows Copy Code

Detection of/*sql injected characters
* All user input data, post parameters, get parameters need to be detected
* Returns the keyword if there is a match to the keyword otherwise false
* This is not the same as the detection of sensitive characters
*/
function Filter_sql ($strData)
{
$strFilter = $blnFlag = $arrayFilter = ";

$strFilter = "' |and| (|)| Exec|insert|select|delete|update|count|*|%27|chr|mid|master|truncate|char|declare|union|or "; The characters that need to be filtered can be added by themselves, "|" is a delimiter
$blnFlag =false; Filter flag, if the filter is generated, then it is true

$arr =explode ("|", $strFilter);
$str = "";

foreach ($arr as $row)
{
$str. =preg_quote ($row). "|";
}

$str =trim ($str, "|");

if (Preg_match ('/'. $str. '/I ', $strData, $word))
{
return $word [0];
}

return false;
}

/*
Test
$string = "FASDF Union";
echo Filter_sql ($string);
*/

?>

http://www.bkjia.com/PHPjc/629696.html www.bkjia.com true http://www.bkjia.com/PHPjc/629696.html techarticle write your own SQL injection detection function, you can effectively detect the user Post,get over the reference to filter, the need for a friend reference. Code to copy code like this? PHP/*sql injection ...

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