Php general anti-injection provision_php tutorial

Source: Internet
Author: User
Recommended php general anti-injection program. Copy the code as follows: functionjk1986_checksql () {$ bad_strand | select | update | delete | insert | *; $ bad_Arrayexplode (|, $ bad_str ); ** filter the Get parameter ** foreach ($ bad _ The code is as follows:


Function jk1986_checksql ()
{
$ Bad_str = "and | select | update | '| delete | insert | *";
$ Bad_Array = explode ("|", $ bad_str );
/** Filter Get parameters **/
Foreach ($ bad_Array as $ bad_a)
{
Foreach ($ _ GET as $ g)
{
If (substr_count (strtolower ($ g), $ bad_a)> 0)
{
Echo "script" alert ('weird character, please do not try to inject this site! Author: Jk1986 QQ: 414028660 '); location. href = 'index. php'; script ";
Exit ();
}
}
}

/** Filter Post parameters **/

Foreach ($ bad_Array as $ bad_a)
{
Foreach ($ _ POST as $ p)
{
If (substr_count (strtolower ($ p), $ bad_a)> 0)
{
Echo "script" alert ('weird character, please do not try to inject this site! Author: Jk1986 QQ: 414028660 '); location. href = 'index. php'; script ";
Exit ();
}
}
}

/** Filter cookie parameters **/

Foreach ($ bad_Array as $ bad_a)
{
Foreach ($ _ COOKIE as $ co)
{
If (substr_count (strtolower ($ co), $ bad_a)> 0)
{
Echo "script" alert ('weird character, please do not try to inject this site! Author: Jk1986 QQ: 414028660 '); location. href = 'index. php'; script ";
Exit ();
}
}
}
}


Like asp and asp.net, the goal is to make lazy and improve efficiency. 88

The http://www.bkjia.com/PHPjc/322907.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322907.htmlTechArticle code is as follows: function jk1986_checksql () {$ bad_str = "and | select | update | '| delete | insert | *"; $ bad_Array = explode ("| ", $ bad_str);/** filter Get parameters **/foreach ($ bad _...

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.