sql注入預防
1.數字型變量:用isNumeric()判斷是否爲數字
2.字符型或其它類型變量:將單引號'替換成兩個
下面給出兩個函數,用來代替ASP的Request函數,只要每處地方使用這兩個函數取值,SQL注入根本沒有用武之地.
'----------------------------------------------------------------
' 獲取數字型參數
'----------------------------------------------------------------
Function ReqNum ( StrName )
ReqNum = Request ( StrName )
if not isNumeric ( ReqNum ) then
response.write "參數必須爲數字型!"
response.end
end if
End Function
'----------------------------------------------------------------
' 獲取字符型參數
'----------------------------------------------------------------
Function ReqStr ( StrName )
ReqStr = Replace ( Request(StrName), "'", "''" )
End Function
2.字符型或其它類型變量:將單引號'替換成兩個
下面給出兩個函數,用來代替ASP的Request函數,只要每處地方使用這兩個函數取值,SQL注入根本沒有用武之地.
'----------------------------------------------------------------
' 獲取數字型參數
'----------------------------------------------------------------
Function ReqNum ( StrName )
ReqNum = Request ( StrName )
if not isNumeric ( ReqNum ) then
response.write "參數必須爲數字型!"
response.end
end if
End Function
'----------------------------------------------------------------
' 獲取字符型參數
'----------------------------------------------------------------
Function ReqStr ( StrName )
ReqStr = Replace ( Request(StrName), "'", "''" )
End Function
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.