血管炎中医能治好吗:“如何使用”SQL过滤代码

来源:百度文库 编辑:中科新闻网 时间:2024/05/04 12:19:21
'**************************************************
' 作用: 严格过滤非法的SQL字符
' 参数: strChar-----要过滤的字符
' 返回: 过滤后的字符
' 时间: 2005-3-8 9:21
' 修改: 无
'**************************************************
Public Function RepBadChar(strChar)
If strChar="" Then
RepBadChar=""
Else RepBadChar=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(strChar,"'",""),"?",""),"(","("),")",")"),"<",""),".","."),">","")," ","")
End if
End function

如何在下文中使用这个代码?

我在文件中这样用:
if RepBadChar(request.QueryString("id"))=False then
response.write"<script>alert(""提交有错误"");location.href=""../index.asp"";</script>"
response.end
end if

然后在网址的“用户名”后面加入',比如:xxx.com/?id=741'

系统为何还提示:

Microsoft JET Database Engine 错误 '80040e14'

字符串的语法错误 在查询表达式 'username ='741''' 中。

呢?

怎么样才能不显示该错误信息?请求帮助中
.

感觉zhidao中的人好象少了,问题没以前回复的多了

就来研究吧

如果id=741,就是显示一个正确的页面(本来如此)
如没有repbadchar这个函数,使用id=741',显示的页面是以下内容:
Microsoft JET Database Engine 错误 '80040e14'

字符串的语法错误 在查询表达式 'username ='741''' 中。

显示使用了repbadchar函数,id=741',所显示的页面还是:

Microsoft JET Database Engine 错误 '80040e14'

字符串的语法错误 在查询表达式 'username ='741''' 中。

应该是正常页面,为何还不正常呢

.

.

Public Function RepBadChar(strChar)
If strChar="" Then
RepBadChar=""
Else
RepBadChar=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(strChar,"'",""),"?",""),"(","("),")",")"),"<",""),".","."),">","")," ","")
End if
End function

dim id
id =request.QueryString("id")
if len(RepBadChar(id))<>len(request.QueryString("id")) then
response.write"<script>alert(""id参数里含有非法字符"");location.href=""../index.asp"";</script>"
response.end
end if

RepBadChar函数不是反回真假值,它不是查找有没有非法字符,他是替换非法字符。
如果你的id=741'的话,
RepBadChar(request.QueryString("id"))的结果是741