asp防止SQL注入函数?怎么用?

来源:百度知道 编辑:UC知道 时间:2024/06/04 08:57:42
网络上很多,但是都没说怎么使用?
如果我有个这样的~

www.www.com/read.asp?type=中文

那么这样怎么防止注入?

1 根据类型来过滤
比如只能输入数字,那么你就写个函数来判断request.querystring("type")是否为数字。同时还要判断这个数字是否超过了最大上限。
如果是字符串,那么你要过滤掉sql里面敏感的字符,比如单引号,双引号之类。
2过滤sql文
你写的是
select * from username where type= "& type
要使用户type 为 "1 or type=admin",你猜猜是什么结果?

----------
防止注入概括起来其实就是
1 类型检查
2 变量范围检查
3 特殊字符过滤
4 sql关键字过滤

Function Checkstr(Str) '防注入函数
If IsNull(Str) or str="" Then
Checkstr = ""
Exit Function
End If
Str = Replace(Str, Chr(0), "")
If (Instr(Str,"select")>0 And Instr(Str,"from")>0) Then
response.write "呵呵,不要黑我!"
response.End
End If
Str = Replace(Str, "'", "'")
Str = Replace(Str, CHR(39), "'")
Str = Replace(Str,"--","-