我的ID型参数过滤防注入之道
判断用户提交的数字参数,诸如**.asp?id=xxx
思路:用户提交的不是数字的情况下(**.asp?id=xxx and 1=1),将后面非数字字符全部过滤
这样,在被注入或发生其他情况时,都能显示正确的数据
下面是函数
Function toNum(str) ' If isNumeric(str) Then ' toNum = cLng(str) ' ElseIf isNull(str) Then If isNull(str) Then toNum = "" Else Dim s,i,ts,ch s = "" ts = str For i = 1 to Len(ts) ch = Mid(ts,i,1) If Asc(ch) >= 48 And Asc(ch) <=57 Then s = s & ch Else Exit For End If Next If Len(s)>0 Then toNum = cLng(s) Else toNum = s End If End If End Function