防SQL注入函数代码
2008-02-23 09:48:07来源:互联网 阅读 ()
'输入:检查字符,传值方式(0直接传,1取Form,2取QueryString,3取cookies,4直接Reqeust),开始数字(默认数字),结束数字(为-1则不检查大小)
Function CheckNum(str_str,int_quest,int_startnum,int_endnum)
mystr=Trim(str_str)
Select Case int_quest
Case 1
istr=Request.Form(mystr)
Case 2
istr=Request.QueryString(mystr)
Case 3
istr=Request.Cookies(mystr)
Case 4
istr=Request(mystr)
Case Else
istr=mystr
End Select
istr=Left(istr,32)
If IsNumeric(istr) Then
iNum=CDbl(istr)
Else
iNum=int_startnum
End If
If int_endnum>-1Then
If iNum<int_startnum Then iNum=int_startnum
If iNum>int_endnum Then iNum=int_endnum
End If
CheckNum=iNum
End Function
'------------------------------------------------
'用途:检查过滤字符串
'输入:字符串,传值方式(0直接传,1取Form,2取QueryString,3取cookies,4直接Reqeust),检查方式(1不过滤html,2纯html,3标题过滤,4其他html过滤,),字符段截取长度
Function CheckStr(str_str,int_quest,int_type,int_strlen)
mystr=str_str
Select Case int_quest
Case 1
istr=Request.Form(mystr)
Case 2
istr=Request.QueryString(mystr)
Case 3
istr=Request.Cookies(mystr)
Case 4
istr=Request(mystr)
Case Else
istr=mystr
End Select
istr=""&Trim(istr)
istr=Replace(istr,"'","''")
Select Case int_type
Case 1
istr=Replace(istr,CHR(32)," ")
istr=Replace(istr,CHR(9)," ")
istr=Replace(istr,CHR(10) & CHR(10),"</P><P> ")
istr=Replace(istr,CHR(10),"<BR> ")
istr=Replace(istr,CHR(13),"")
Case 2
istr=istr
Case 3
istr=Replace(istr,CHR(32)," ")
istr=Replace(istr,CHR(9)," ")
istr=Replace(istr,CHR(13), "")
istr=Replace(istr,"<","<")
istr=Replace(istr,">",">")
istr=Replace(istr,CHR(34),""")
istr=Replace(istr," "," ")
istr=Replace(istr,CHR(39), "'")
Case Else
istr=Replace(istr,CHR(32)," ")
istr=Replace(istr,CHR(9)," ")
istr=Replace(istr,CHR(10) & CHR(10), "</P><P> ")
istr=Replace(istr,CHR(10), "<BR> ")
istr=Replace(istr,CHR(13), "")
istr=Replace(istr,"<","<")
istr=Replace(istr,">",">")
istr=Replace(istr,CHR(34),""")
istr=Replace(istr," "," ")
istr=Replace(istr,CHR(39), "'")
End select
istr=CutStr(istr,int_strlen,"")
CheckStr=istr
End Function
'------------------------------------------------
'用途:截取字符串
'输入:字符串,字符段截取长度,超过部分字符
Function CutStr(str_str,int_strlen,str_addtrr)
Dim k,i
k=0
For i=1 to Len(str_str)
c=Abs(Asc(Mid(str_str,i,1)))
If c>255 Then
k=k 2
Else
k=k 1
End If
If k>=int_strlen Then Exit For
Next
CutStr=Left(str_str,k)&str_addtrr
End Function
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash