再次发布一个防sql注入的asp函数,代码如下:
'功能防sql注入,包括字符型变量和数字型变量。
'参数:
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)
'lenlimit:长度限制
'整理:www.aspprogram.cn
'原创文章,转载请保留此信息。
Function SafeRequest(ParaName,ParaType,lenlimit)
 Dim ParaValue
 ParaValue = trim(Request(ParaName))
 If ParaType = 1 then
  If IsNull(ParaValue) Or (Not IsNumeric(ParaValue)) then
   ParaValue = lenlimit
  End if
 Else
  If IsNull(ParaValue) Then
   ParaValue = ""
  Else
   Dim strBadChar, arrBadChar, tempChar, i
   strBadChar = "+,',--,^," & Chr(34) & "," & Chr(0) & ""
   arrBadChar = Split(strBadChar, ",")
   tempChar = ParaValue
   For i = 0 To UBound(arrBadChar)
    tempChar = Replace(tempChar, arrBadChar(i), "")
   Next
   tempChar = Replace(tempChar, "@@", "@")
   If lenlimit <> -1 Then
    tempChar = Left(tempChar,lenlimit)
   End If
   ParaValue = tempChar
  End If
 End If
 SafeRequest = ParaValue
End Function
使用方法:
当我要获取一个字符型变量str
value=saferequest("str",0,50)
这句的意思是:获取参数str中的值,只获取前50个字符,超过的丢失,并对那些特殊符号进行了过滤。
当我要获取一个数字型变量str
value=saferequest("str",1,0)
这句的意思是:获取参数str中的值,并进行数字判断,不是数字的或者为空的时候,value就等于0,否则,value等于request("str")的值。
