asp通用安全字符串输入替换server.htmlencode
作者:寒川 发布于:2008-4-8 13:33 Tuesday 分类:网页编程
<%
' ============================================
' 通用安全字符串输入,彻底替换server.htmlencode
' ============================================
Function HTMLEncode(Str)
If Isnull(Str) Then
HTMLEncode = ""
Exit Function
End If
Str = Replace(Str,Chr(0),"", 1, -1, 1)
Str = Replace(Str, """", """, 1, -1, 1)
Str = Replace(Str,"<","<", 1, -1, 1)
Str = Replace(Str,">",">", 1, -1, 1)
Str = Replace(Str, "script", "script", 1, -1, 0)
Str = Replace(Str, "SCRIPT", "SCRIPT", 1, -1, 0)
Str = Replace(Str, "Script", "Script", 1, -1, 0)
Str = Replace(Str, "script", "Script", 1, -1, 1)
Str = Replace(Str, "object", "object", 1, -1, 0)
Str = Replace(Str, "OBJECT", "OBJECT", 1, -1, 0)
Str = Replace(Str, "Object", "Object", 1, -1, 0)
Str = Replace(Str, "object", "Object", 1, -1, 1)
Str = Replace(Str, "applet", "applet", 1, -1, 0)
Str = Replace(Str, "APPLET", "APPLET", 1, -1, 0)
Str = Replace(Str, "Applet", "Applet", 1, -1, 0)
Str = Replace(Str, "applet", "Applet", 1, -1, 1)
Str = Replace(Str, "[", "[")
Str = Replace(Str, "]", "]")
Str = Replace(Str, """", "", 1, -1, 1)
Str = Replace(Str, "=", "=", 1, -1, 1)
Str = Replace(Str, "'", "''", 1, -1, 1)
Str = Replace(Str, "select", "select", 1, -1, 1)
Str = Replace(Str, "execute", "execute", 1, -1, 1)
Str = Replace(Str, "exec", "exec", 1, -1, 1)
Str = Replace(Str, "join", "join", 1, -1, 1)
Str = Replace(Str, "union", "union", 1, -1, 1)
Str = Replace(Str, "where", "where", 1, -1, 1)
Str = Replace(Str, "insert", "insert", 1, -1, 1)
Str = Replace(Str, "delete", "delete", 1, -1, 1)
Str = Replace(Str, "update", "update", 1, -1, 1)
Str = Replace(Str, "like", "like", 1, -1, 1)
Str = Replace(Str, "drop", "drop", 1, -1, 1)
Str = Replace(Str, "create", "create", 1, -1, 1)
Str = Replace(Str, "rename", "rename", 1, -1, 1)
Str = Replace(Str, "count", "count", 1, -1, 1)
Str = Replace(Str, "chr", "chr", 1, -1, 1)
Str = Replace(Str, "mid", "mid", 1, -1, 1)
Str = Replace(Str, "truncate", "truncate", 1, -1, 1)
Str = Replace(Str, "nchar", "nchar", 1, -1, 1)
Str = Replace(Str, "char", "char", 1, -1, 1)
Str = Replace(Str, "alter", "alter", 1, -1, 1)
Str = Replace(Str, "cast", "cast", 1, -1, 1)
Str = Replace(Str, "exists", "exists", 1, -1, 1)
Str = Replace(Str,Chr(13),"<br>", 1, -1, 1)
HTMLEncode = Replace(Str,"'","''", 1, -1, 1)
End Function
%>
把上面代码保存为新的文件,包括到需要转换的页面,调用方式:HTMLEncode("字符串")
日志分类
最近日志
随机日志
最新评论
- CCC certification
对这块还真是不... - 那风筝
happy new year ! - Roy
你好, 交换个链... - 太阳城娱乐网
说实话,对钛白... - 卡特&&艾弗森
不错啊!!,过段... - 奇遇
沙发 - 寒川
@Mr.邱℡:现在可... - Mr.邱℡
曾经加过,失效... - 寒川
@欧盛网络:链接... - 欧盛网络
换个链接好不?...
日志档案
- 2011年11月(2)
- 2011年9月(1)
- 2011年8月(2)
- 2011年7月(2)
- 2011年5月(1)
- 2011年3月(3)
- 2011年2月(2)
- 2010年12月(1)
- 2010年11月(2)
- 2010年10月(3)
- 2010年9月(9)
- 2010年8月(8)
- 2010年7月(13)
- 2010年6月(18)
- 2010年5月(24)
- 2010年4月(10)
- 2010年3月(14)
- 2010年2月(6)
- 2010年1月(7)
- 2009年11月(2)
- 2009年10月(3)
- 2009年9月(3)
- 2009年8月(8)
- 2009年7月(15)
- 2009年6月(14)
- 2009年4月(2)
- 2008年12月(1)
- 2008年6月(1)
- 2008年5月(10)
- 2008年4月(9)
- 2008年3月(5)
- 2008年2月(2)
- 2008年1月(5)
- 2007年12月(4)
- 2006年9月(6)
- 2006年7月(1)



发表评论: