这段代码 中间连接数据库,其他的不是很清楚,有谁讲解一下吗?

win7cc 2010-07-16 08:55:48
<%
'On Error Resume Next
dim ServerPath
ServerPath = Request.ServerVariables("URL")
ServerPath = Split(LCase(ServerPath),"/manage/")(0)
ServerPath = "/"

dim DbPath,Pwd,conn
DbPath = SERVER.MapPath(ServerPath&"Data/Data.mdb")
Set conn= Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& DbPath
'response.Write dbpath
Call GetSiteInfo()

if Err then
Err.Clear
'response.Write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>")
PMsg="数据库连接错误!请检查连接字串!"
'Call PopMsg("连接数据库")
end if

Sub CloseConn()
conn.close()
set conn=nothing
end sub

if request("repl")<>"off" then
Call ChkData()
end if

sub ChkData()
'--------定义部份------------------
Dim XH_Post,XH_Get,XH_In,XH_Inf,XH_Xh,XH_db,XH_dbstr
'自定义需要过滤的字串,用 "|" 分隔
XH_In = "'|;|exec|insert|select|delete%20from|update|count|*|%|chr|mid|master|truncate|char|declare|drop%20table|from|net%20user|xp_cmdshell|/add|net%20localgroup%20administrators|Asc|char"
'----------------------------------
XH_Inf = split(XH_In,"|")
'--------POST部份------------------
if Request.Form<>"" Then
For Each XH_Post In Request.Form
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.Form(XH_Post)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------

'--------GET部份-------------------
if Request.QueryString<>"" Then
For Each XH_Get In Request.QueryString
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.QueryString(XH_Get)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------
end sub%>


这段代码 中间连接数据库,其他的不是很清楚,有谁讲解一下吗?
...全文
14 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zj_JavaBean 2010-07-16
好像是为了安全过滤一些SQL关键字 防注入吧
'--------POST部份------------------
if Request.Form<>"" Then
For Each XH_Post In Request.Form
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.Form(XH_Post)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------

'--------GET部份-------------------
if Request.QueryString<>"" Then
For Each XH_Get In Request.QueryString
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.QueryString(XH_Get)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------
end sub%>

两种传值的处理
回复
ChinaXtHuLang 2010-07-16
关闭数据库链接
Sub CloseConn()
conn.close()
set conn=nothing
end sub

防止攻击注入
if request("repl")<>"off" then
Call ChkData()
end if

sub ChkData()
'--------定义部份------------------
Dim XH_Post,XH_Get,XH_In,XH_Inf,XH_Xh,XH_db,XH_dbstr
'自定义需要过滤的字串,用 "|" 分隔
XH_In = "'|;|exec|insert|select|delete%20from|update|count|*|%|chr|mid|master|truncate|char|declare|drop%20table|from|net%20user|xp_cmdshell|/add|net%20localgroup%20administrators|Asc|char"
'----------------------------------
XH_Inf = split(XH_In,"|")
'--------POST部份------------------
if Request.Form<>"" Then
For Each XH_Post In Request.Form
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.Form(XH_Post)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------

'--------GET部份-------------------
if Request.QueryString<>"" Then
For Each XH_Get In Request.QueryString
For XH_Xh=0 To Ubound(XH_Inf)
if Instr(LCase(Request.QueryString(XH_Get)),XH_Inf(XH_Xh))<>0 Then
PMsg = "处理数据时发生错误!<br />数据类型不匹配!"
Call PopMsg("数据类型")
End if
Next
Next
End if
'----------------------------------
end sub
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告