zoukankan      html  css  js  c++  java
  • PHP通用的防注入过滤用户字符串函数

    PHP通用的防注入过滤用户字符串函数

    今天做完了整个php项目,想来安全问题不少,开发程序的过程中无心过滤参数。所以注入少不了,才有了下面的防注入程序。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    function jk1986_checksql()  
    {  
    $bad_str = "and|select|update|'|delete|insert|*";  
    $bad_Array = explode("|",$bad_str);  
    /** 过滤Get参数 **/
    foreach ($bad_Array as $bad_a)  
    {  
       foreach ($_GET as $g)  
        {  
         if (substr_count(strtolower($g),$bad_a) > 0)  
         {  
         echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";  
         exit();  
         }  
         }  
    }  
          
    /** 过滤Post参数 **/
          
        foreach ($bad_Array as $bad_a)  
       {  
       foreach ($_POST as $p)  
         {  
         if (substr_count(strtolower($p),$bad_a) > 0)  
         {  
         echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";  
         exit();  
         }  
         }  
       }  
            
        /** 过滤Cookies参数 **/
          
        foreach ($bad_Array as $bad_a)  
       {  
       foreach ($_COOKIE as $co)  
         {  
         if (substr_count(strtolower($co),$bad_a) > 0)  
         {  
         echo "<script>alert('诡异字符,请不要尝试注入本站! 作者:Jk1986 QQ:414028660');location.href='index.php';</script>";  
         exit();  
         }  
         }  
       }    
    }
  • 相关阅读:
    路径不对 导致FileNotFoundError: [WinError 2] 系统找不到指定的文件, 问题解决办法
    pycharm + selenium + python 提示 Unresolved reference 'webdriver' 解决办法
    highstock实现股票分时
    jquery 源码剖析1
    html 其它标签
    html5 基本内容 摘自W3C
    html总结
    web性能 部分
    linux常用命令 3
    linux常用命令 2
  • 原文地址:https://www.cnblogs.com/fx2008/p/2974944.html
Copyright © 2011-2022 走看看