• 全都有综合资源网

    分享赚钱

    一个专业的免费资源网

    每天更新100+优质资源

  • 手机版二维码

    随时手机查素材

  • 扫描二维码

    加入官方微信群

php防sql注入过滤代码的方法

技术文章 每日更新
2024-7-22 20:51 45人浏览 0人回复
原作者: 全都有综合资源网 来自: 全都有综合资源网 收藏 分享 邀请
摘要

code防止sql注入的函数,过滤掉那些非法的字符,提高sql安全性,同时也可以过滤XSS的攻击。functionfilter($str){if(empty($str))returnfalse;$str=htmlspecialchars($str);$str=str_replace('/',"",$str);$str=str_r ...

 
layui-box layui-code-view" style="margin-top: 0px; margin-bottom: 10px; padding: 9.5px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); white-space: pre-wrap; overflow-wrap: break-word; box-sizing: border-box; position: relative; font-size: 13px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); color: rgb(51, 51, 51); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; overflow: auto; line-height: 1.42857; word-break: break-all; border-radius: 4px;">

code

  1. 避免sql注入的函数,过滤掉那些不法的字符,进步sql平安性,同时也可以过滤XSS的进犯。
  2. function filter($str)
  3. {
  4.     if (empty($str)) return false;
  5.     $str = HTMLspecialchars($str);
  6.     $str = str_replace( '/', "", $str);
  7.     $str = str_replace( '"', "", $str);
  8.     $str = str_replace( '(', "", $str);
  9.     $str = str_replace( ')', "", $str);
  10.     $str = str_replace( 'CR', "", $str);
  11.     $str = str_replace( 'ASCII', "", $str);
  12.     $str = str_replace( 'ASCII 0x0d', "", $str);
  13.     $str = str_replace( 'LF', "", $str);
  14.     $str = str_replace( 'ASCII 0x0a', "", $str);
  15.     $str = str_replace( ',', "", $str);
  16.     $str = str_replace( '%', "", $str);
  17.     $str = str_replace( ';', "", $str);
  18.     $str = str_replace( 'eval', "", $str);
  19.     $str = str_replace( 'open', "", $str);
  20.     $str = str_replace( 'sysopen', "", $str);
  21.     $str = str_replace( 'system', "", $str);
  22.     $str = str_replace( '$', "", $str);
  23.     $str = str_replace( "'", "", $str);
  24.     $str = str_replace( "'", "", $str);
  25.     $str = str_replace( 'ASCII 0x08', "", $str);
  26.     $str = str_replace( '"', "", $str);
  27.     $str = str_replace( '"', "", $str);
  28.     $str = str_replace("", "", $str);
  29.     $str = str_replace("&gt", "", $str);
  30.     $str = str_replace("&lt", "", $str);
  31.     $str = str_replace("<SCRIPT>", "", $str);
  32.     $str = str_replace("</SCRIPT>", "", $str);
  33.     $str = str_replace("<script>", "", $str);
  34.     $str = str_replace("</script>", "", $str);
  35.     $str = str_replace("select","",$str);
  36.     $str = str_replace("join","",$str);
  37.     $str = str_replace("union","",$str);
  38.     $str = str_replace("where","",$str);
  39.     $str = str_replace("insert","",$str);
  40.     $str = str_replace("delete","",$str);
  41.     $str = str_replace("update","",$str);
  42.     $str = str_replace("like","",$str);
  43.     $str = str_replace("drop","",$str);
  44.     $str = str_replace("DROP","",$str);
  45.     $str = str_replace("create","",$str);
  46.     $str = str_replace("modify","",$str);
  47.     $str = str_replace("rename","",$str);
  48.     $str = str_replace("alter","",$str);
  49.     $str = str_replace("cas","",$str);
  50.     $str = str_replace("&","",$str);
  51.     $str = str_replace(">","",$str);
  52.     $str = str_replace("<","",$str);
  53.     $str = str_replace(" ",chr(32),$str);
  54.     $str = str_replace(" ",chr(9),$str);
  55.     $str = str_replace("    ",chr(9),$str);
  56.     $str = str_replace("&",chr(34),$str);
  57.     $str = str_replace("'",chr(39),$str);
  58.     $str = str_replace("<br />",chr(13),$str);
  59.     $str = str_replace("''","'",$str);
  60.     $str = str_replace("css","'",$str);
  61.     $str = str_replace("CSS","'",$str);
  62.     $str = str_replace("<!--","",$str);
  63.     $str = str_replace("convert","",$str);
  64.     $str = str_replace("md5","",$str);
  65.     $str = str_replace("passwd","",$str);
  66.     $str = str_replace("password","",$str);
  67.     $str = str_replace("../","",$str);
  68.     $str = str_replace("./","",$str);
  69.     $str = str_replace("Array","",$str);
  70.     $str = str_replace("or 1='1'","",$str);
  71.     $str = str_replace(";set|set&set;","",$str);
  72.     $str = str_replace("`set|set&set`","",$str);
  73.     $str = str_replace("--","",$str);
  74.     $str = str_replace("OR","",$str);
  75.     $str = str_replace('"',"",$str);
  76.     $str = str_replace("*","",$str);
  77.     $str = str_replace("-","",$str);
  78.     $str = str_replace("+","",$str);
  79.     $str = str_replace("/","",$str);
  80.     $str = str_replace("=","",$str);
  81.     $str = str_replace("'/","",$str);
  82.     $str = str_replace("-- ","",$str);
  83.     $str = str_replace(" -- ","",$str);
  84.     $str = str_replace(" --","",$str);
  85.     $str = str_replace("(","",$str);
  86.     $str = str_replace(")","",$str);
  87.     $str = str_replace("{","",$str);
  88.     $str = str_replace("}","",$str);
  89.     $str = str_replace("-1","",$str);
  90.     $str = str_replace("1","",$str);
  91.     $str = str_replace(".","",$str);
  92.     $str = str_replace("response","",$str);
  93.     $str = str_replace("write","",$str);
  94.     $str = str_replace("|","",$str);
  95.     $str = str_replace("`","",$str);
  96.     $str = str_replace(";","",$str);
  97.     $str = str_replace("etc","",$str);
  98.     $str = str_replace("root","",$str);
  99.     $str = str_replace("//","",$str);
  100.     $str = str_replace("!=","",$str);
  101.     $str = str_replace("$","",$str);
  102.     $str = str_replace("&","",$str);
  103.     $str = str_replace("&&","",$str);
  104.     $str = str_replace("==","",$str);
  105.     $str = str_replace("#","",$str);
  106.     $str = str_replace("@","",$str);
  107.     $str = str_replace("mailto:","",$str);
  108.     $str = str_replace("CHAR","",$str);
  109.     $str = str_replace("char","",$str);
  110.     return $str;
  111. }
  112.  
  113.  
  114. 加倍简洁的避免sql注入的方式(保举利用这个):
  115.  
  116.  if (!get_magic_quotes_gpc()) // 判定magic_quotes_gpc能否为翻开     
  117.  {     
  118.     $post = addslashes($name); // magic_quotes_gpc没有翻开的时辰把数据过滤     
  119.  }     
  120.  
  121.  $name = str_replace("_", "\_", $name); // 把 '_'过滤掉   
  122.    
  123.  $name = str_replace("%", "\%", $name); // 把' % '过滤掉     
  124.  
  125.  $name = nl2br($name); // 回车转换     
  126.  
  127.  $name= htmlspecialchars($name); // html标志转换    
  128.      
  129.  return $name;

php防sql注入过滤代码的方式2869 作者:全都有综合资本网 来历:全都有综合资本网 公布时候:2024-7-22 20:51

©版权免责声明
1、本站所有资源均来自用户上传及互联网。 如有侵权,请联系站长!
2、分享目的仅供大家学习交流。 下载后必须在24小时内删除!
3、不得用于非法商业目的或违反国家法律。 否则,后果自负!
4、本站提供的源代码、模板、插件等资源不包含技术服务。 敬请谅解!
5.如果出现无法下载、无效或有广告的链接,请联系管理员寻求帮助!
6、本站资源价格仅用于赞助,所收取的费用仅用于维持本站日常运营!
7、如果遇到加密压缩包,请使用WINRAR解压。 如果遇到无法解压的加密压缩包,请联系管理员!
8、由于精力有限,很多源代码无法详细测试(解密),部分源代码无法区分为病毒或误报,所以没有进行修改。 请在使用前进行筛选。

路过

雷人

握手

鲜花

鸡蛋
热门教程
专业的免费源码资源分享平台
每天更新100+资源

招募版主发工资

  • 官方在线客服

    QQ客服:红颜

    点击交谈

    在线客服:良子

    点击交谈

    在线客服:闵月

    点击交谈
  • 上海市虹口区海伦中心B座4F4055-4056室

  • 手机扫码查看手机版

    手机查找资源更方便

  • 扫一扫关注官方微信公众号

    加入官方微信

一个专业的免费源码资源互联网分享平台 ©2001-2024 https://www.douyouvip.com全都有综合资源网( 豫ICP备2024057239号-1 )赞助会员|网站地图 HTML
全都有综合资源网,WordPress主题PHP源码,PHP网站源码,网站模板,软件源码,网站源码免费下载,免费网站源码,网站源码模板,免费网站源码下载,wp免费源码,wp免费主题下载,PHP企业网站源码,软件源码下载