我们在注册的时候经常需要判断客户输入的内容是否合法,或者在页面传递参数的时候要判断,是否有客户恶意添加参数进行SQL注入等,这就需要1个函数去判断检测。
' ============================================ ' 判断是否安全字符串,在注册登录等特殊字段中使用 ' ============================================ Function IsSafeStr(str) Dim s_BadStr, n, i s_BadStr = "' &<>" & Chr(34) & Chr(9) & Chr(32) n = Len(s_BadStr) IsSafeStr = True For i = 1 To n If Instr(str, Mid(s_BadStr, i, 1)) > 0 Then IsSafeStr = False Exit Function End If Next End Function
大家可以自行添加BadStr字符串里面的字符,增加你想要过滤的字符即可。
下面是其他网友的补充
'===================================== 
'转换内容,防止意外 
'===================================== 
Function Content_Encode(ByVal t0) 
IF IsNull(t0) Or Len(t0)=0 Then 
Content_Encode="" 
Else 
Content_Encode=Replace(t0,"<","<") 
Content_Encode=Replace(Content_Encode,">",">") 
End IF 
End Function 
'===================================== 
'反转换内容 
'===================================== 
Function Content_Decode(ByVal t0) 
IF IsNull(t0) Or Len(t0)=0 Then 
Content_Decode="" 
Else 
Content_Decode=Replace(t0,"<","<") 
Content_Decode=Replace(Content_Decode,">",">") 
End IF 
End Function 
'===================================== 
'过滤字符 
'===================================== 
Function FilterText(ByVal t0,ByVal t1) 
IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterText="":Exit Function 
t0=Trim(t0) 
Select Case t1 
Case "1" 
t0=Replace(t0,Chr(32)," ") 
t0=Replace(t0,Chr(13),"") 
t0=Replace(t0,Chr(10)&Chr(10),"<br>") 
t0=Replace(t0,Chr(10),"<br>") 
Case "2" 
t0=Replace(t0,Chr(8),"")'回格 
t0=Replace(t0,Chr(9),"")'tab(水平制表符) 
t0=Replace(t0,Chr(10),"")'换行 
t0=Replace(t0,Chr(11),"")'tab(垂直制表符) 
t0=Replace(t0,Chr(12),"")'换页 
t0=Replace(t0,Chr(13),"")'回车 chr(13)&chr(10) 回车和换行的组合 
t0=Replace(t0,Chr(22),"") 
t0=Replace(t0,Chr(32),"")'空格 SPACE 
t0=Replace(t0,Chr(33),"")'! 
t0=Replace(t0,Chr(34),"")'" 
t0=Replace(t0,Chr(35),"")'# 
t0=Replace(t0,Chr(36),"")'$ 
t0=Replace(t0,Chr(37),"")'% 
t0=Replace(t0,Chr(38),"")'& 
t0=Replace(t0,Chr(39),"")'' 
t0=Replace(t0,Chr(40),"")'( 
t0=Replace(t0,Chr(41),"")') 
t0=Replace(t0,Chr(42),"")'* 
t0=Replace(t0,Chr(43),"")'+ 
t0=Replace(t0,Chr(44),"")', 
t0=Replace(t0,Chr(45),"")'- 
t0=Replace(t0,Chr(46),"")'. 
t0=Replace(t0,Chr(47),"")'/ 
t0=Replace(t0,Chr(58),"")': 
t0=Replace(t0,Chr(59),"")'; 
t0=Replace(t0,Chr(60),"")'< 
t0=Replace(t0,Chr(61),"")'= 
t0=Replace(t0,Chr(62),"")'> 
t0=Replace(t0,Chr(63),"")'"")'@ 
t0=Replace(t0,Chr(91),"")'\ 
t0=Replace(t0,Chr(92),"")'\ 
t0=Replace(t0,Chr(93),"")'] 
t0=Replace(t0,Chr(94),"")'^ 
t0=Replace(t0,Chr(95),"")'_ 
t0=Replace(t0,Chr(96),"")'` 
t0=Replace(t0,Chr(123),"")'{ 
t0=Replace(t0,Chr(124),"")'| 
t0=Replace(t0,Chr(125),"")'} 
t0=Replace(t0,Chr(126),"")'~ 
Case Else 
t0=Replace(t0, "&", "&") 
t0=Replace(t0, "'", "'") 
t0=Replace(t0, """", """) 
t0=Replace(t0, "<", "<") 
t0=Replace(t0, ">", ">") 
End Select 
IF Instr(Lcase(t0),"expression")>0 Then 
t0=Replace(t0,"expression","e­xpression", 1, -1, 0) 
End If 
FilterText=t0 
End Function 
'===================================== 
'过滤常见字符及Html 
'===================================== 
Function FilterHtml(ByVal t0) 
IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterHtml="":Exit Function 
IF Len(Sdcms_Badhtml)>0 Then t0=ReplaceText(t0,"<(\/|)("&Sdcms_Badhtml&")", "<$1$2") 
IF Len(Sdcms_BadEvent)>0 Then t0=ReplaceText(t0,"<(.[^>]*)("&Sdcms_BadEvent&")", "<$1$2") 
t0=FilterText(t0,0) 
FilterHtml=t0 
End Function 
Function GotTopic(ByVal t0,ByVal t1) 
IF Len(t0)=0 Or IsNull(t0) Then 
GotTopic="" 
Exit Function 
End IF 
Dim l,t,c, i 
t0=Replace(Replace(Replace(Replace(t0," "," "),""",chr(34)),">",">"),"<","<") 
l=Len(t0) 
t=0 
For I=1 To l 
c=Abs(Asc(Mid(t0,i,1))) 
IF c>255 Then t=t+2 Else t=t+1 
IF t>=t1 Then 
gotTopic=Left(t0,I)&"…" 
Exit For 
Else 
GotTopic=t0 
End IF 
Next 
GotTopic=Replace(Replace(Replace(Replace(GotTopic," "," "),chr(34),"""),">",">"),"<","<") 
End Function 
Function UrlDecode(ByVal t0) 
Dim t1,t2,t3,i,t4,t5,t6 
t1="" 
t2=False 
t3="" 
For I=1 To Len(t0) 
t4=Mid(t0,I,1) 
IF t4="+" Then 
t1=t1&" " 
ElseIF t4="%" Then 
t5=Mid(t0,i+1,2) 
t6=Cint("&H" & t5) 
IF t2 Then 
t2=False 
t1=t1&Chr(Cint("&H"&t3&t5)) 
Else 
IF Abs(t6)<=127 then 
t1=t1&Chr(t6) 
Else 
t2=True 
t3=t5 
End IF 
End IF 
I=I+2 
Else 
t1=t1&t4 
End IF 
Next 
UrlDecode=t1 
End Function 
Function CutStr(byVal t0,byVal t1) 
Dim l,t,c,i 
IF IsNull(t0) Then CutStr="":Exit Function 
l=Len(t0) 
t1=Int(t1) 
t=0 
For I=1 To l 
c=Asc(Mid(t0,I,1)) 
IF c<0 Or c>255 Then t=t+2 Else t=t+1 
IF t>=t1 Then 
CutStr=Left(t0,I)&"..." 
Exit For 
Else 
CutStr=t0 
End IF 
Next 
End Function 
Function CloseHtml(ByVal t0) 
Dim t1,I,t2,t3,Regs,Matches,J,Match 
Set Regs=New RegExp 
Regs.IgnoreCase=True 
Regs.Global=True 
t1=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3","h4","h5","h6") 
For I=0 To UBound(t1) 
t2=0 
t3=0 
Regs.Pattern="\<"&t1(I)&"( [^\<\>]+|)\>" 
Set Matches=Regs.Execute(t0) 
For Each Match In Matches 
t2=t2+1 
Next 
Regs.Pattern="\</"&t1(I)&"\>" 
Set Matches=Regs.Execute(t0) 
For Each Match In Matches 
t3=t3+1 
Next 
For j=1 To t2-t3 
t0=t0+"</"&t1(I)&">" 
Next 
Next 
CloseHtml=t0 
End Function
以上就是asp中常用的字符串安全处理函数集合(过滤特殊字符等)的详细内容,更多关于字符串 安全处理的资料请关注其它相关文章!
                                    标签:
                                        
                            字符串,安全处理
                                免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
                                如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
                            
                        暂无“asp中常用的字符串安全处理函数集合(过滤特殊字符等)”评论...
                                    稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新动态
2025年11月04日
                                2025年11月04日
                    - 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
 - 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
 - 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
 - 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
 - 群星《2024好听新歌42》AI调整音效【WAV分轨】
 - 王思雨-《思念陪着鸿雁飞》WAV
 - 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
 - 李健《无时无刻》[WAV+CUE][590M]
 - 陈奕迅《酝酿》[WAV分轨][502M]
 - 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
 - 群星《吉他王(黑胶CD)》[WAV+CUE]
 - 齐秦《穿乐(穿越)》[WAV+CUE]
 - 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
 - 邝美云《邝美云精装歌集》[DSF][1.6G]
 - 吕方《爱一回伤一回》[WAV+CUE][454M]