我写我滴,你看你滴,大家互不侵犯!~~

站点统计

  • 文章总数:180
  • 评论总数:533
  • 引用总数:1
  • 浏览总数:570962
  • 留言总数:85
  • 当前主题:MsnSpace
  • 当前样式:MsnSpace

站内搜索

Google

图标汇集

  • 本站的FeedBurner RSS Feed Add to Google Reader
  • Add to BlogLines
  • Blog Directory 本站支持 WAP 访问,地址:http://www.bkye.com/wap
  • AXNA 通过 W3C XHTML 校验
  • UTF-8 编码 防广告链接
  • 订阅本站的 RSS 2.0 新闻聚合 Google SiteMap
  •         
« 买手机最应该注意的问题将PPT文件转换为WORD文档 »

ASP中过滤SQL字符

主要代码如下:

function POP_sqlin(text)  
  if isnull(text) then
    POP_sqlin=""
    exit function
  end if

  dim Sqlwords
  Set Sqlwords=new RegExp
  Sqlwords.IgnoreCase =True
  Sqlwords.Global=True

  Sqlwords.Pattern="(')"
  text=Sqlwords.Replace(text,"''")
  Sqlwords.Pattern="(;)"
  text=Sqlwords.Replace(text,";")
  Sqlwords.Pattern="(%)"
  text=Sqlwords.Replace(text,"%")
  Sqlwords.Pattern="(and)"
  text=Sqlwords.Replace(text,"and")
  Sqlwords.Pattern="(exec)"
  text=Sqlwords.Replace(text,"exec")
  Sqlwords.Pattern="(execute)"
  text=Sqlwords.Replace(text,"execute")
  Sqlwords.Pattern="(insert)"
  text=Sqlwords.Replace(text,"insert")
  Sqlwords.Pattern="(select)"
  text=Sqlwords.Replace(text,"select")
  Sqlwords.Pattern="(delete)"
  text=Sqlwords.Replace(text,"delete")
  Sqlwords.Pattern="(update)"
  text=Sqlwords.Replace(text,"update")
  Sqlwords.Pattern="(count)"
  text=Sqlwords.Replace(text,"count")
  Sqlwords.Pattern="(chr)"
  text=Sqlwords.Replace(text,"chr")
  Sqlwords.Pattern="(mid)"
  text=Sqlwords.Replace(text,"mid")
  Sqlwords.Pattern="(master)"
  text=Sqlwords.Replace(text,"master")
  Sqlwords.Pattern="(truncate)"
  text=Sqlwords.Replace(text,"truncate")
  Sqlwords.Pattern="(char)"
  text=Sqlwords.Replace(text,"char")
  Sqlwords.Pattern="(declare)"
  text=Sqlwords.Replace(text,"declare")

  Set Sqlwords=Nothing
  POP_sqlin = text
end function

function POP_sqlout(text)  
  if isnull(text) then
    POP_sqlout=""
    exit function
  end if
  text = Replace(text,"''","'")
  text = Replace(text,";",";")
  text = Replace(text,"%","%")
  text = Replace(text,"and","and")
  text = Replace(text,"exec","exec")
  text = Replace(text,"execute","execute")
  text = Replace(text,"insert","insert")
  text = Replace(text,"select","select")
  text = Replace(text,"delete","delete")
  text = Replace(text,"update","update")
  text = Replace(text,"count","count")
  text = Replace(text,"chr","chr")
  text = Replace(text,"mid","mid")
  text = Replace(text,"master","master")
  text = Replace(text,"truncate","truncate")
  text = Replace(text,"char","char")
  text = Replace(text,"declare","declare")
  POP_sqlout = text
end function

function HTMLEncode(popstring)
  if not isnull(popstring) then
  popstring = POP_sqlout(popstring)
  popstring = replace(popstring, ">", ">")
  popstring = replace(popstring, "<", "<")
  popstring = Replace(popstring, CHR(32), " ")
  popstring = Replace(popstring, CHR(9), " ")
  popstring = Replace(popstring, CHR(34), """)
  popstring = Replace(popstring, CHR(39), "'")
  popstring = Replace(popstring, CHR(10) & CHR(10), "</p><p> ")
  popstring = Replace(popstring, CHR(10), "<br /> ")
  popstring = Replace(popstring, CHR(36), "$")
  HTMLEncode = popstring
  end if
end function



使用方法:
把需要过滤的提交信息改为POP_sqlin(提交的信息)即可
在需要把信息还原时改为:Htmlencode(提交的信息)即可

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

MsnSpace Design By Erentan, Powered By Z-Blog 1.8, 晋ICP备05007264号

Copyright © 2005-2008 Bkye.Com. All Rights Reserved. TOP