Two simple PHP anti-SQL injection Code _php tutorial

Source: Internet
Author: User
Introduce two methods, first, save the following code as safe.php in the root directory of the Web site, and then add an include ("/safe.php") in front of each PHP file:

PHP Anti-Injection code method one:

 
  $value) {if (Eregi ($value, $StrFiltrate)) {return true;}} return false;} Merge $_post and $_getif (function_exists (Array_merge)) {$ArrPostAndGet =array_merge ($HTTP _post_vars, $HTTP _get_vars);} Else{foreach ($HTTP _post_vars as $key = $value) {$ArrPostAndGet []= $value;} foreach ($HTTP _get_vars as $key = + $value) {$ArrPostAndGet []= $value;}} Verify the start of the foreach ($ArrPostAndGet as $key = = $value) {if (Funstringexist ($value, $ArrFiltrate)) {echo ""; if (Emptyempty ($ Strgourl) {echo "";} Else{echo "";} Exit;}}? >

PHP Anti-Injection code method two:

 
  $get _var) {if (Is_numeric ($get _var)) {$get [Strtolower ($get _key)] = Get_int ($get _var);} else {$get [Strtolower ($get _key )] = Get_str ($get _var);}} /* Filter all POST-over variable */foreach ($_post as $post _key=> $post _var) {if (Is_numeric ($post _var)) {$post [Strtolower ($post _key )] = Get_int ($post _var);} else {$post [Strtolower ($post _key)] = Get_str ($post _var);}} /* Filter function *///integer filter function get_int ($number) {return intval ($number);} String filter functions function Get_str ($string) {if (!GET_MAGIC_QUOTES_GPC ()) {return addslashes ($string);} return $string;}? >

http://www.bkjia.com/PHPjc/752508.html www.bkjia.com true http://www.bkjia.com/PHPjc/752508.html techarticle introduce two methods, first, save the following code as safe.php in the root directory of the Web site, and then add the include ("/safe.php") in front of each PHP file, you can: PHP anti-injection code method one: ...

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