教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp  >  正文 asp常用的安全过滤判断函数

asp常用的安全过滤判断函数

发布时间:2016-10-15   编辑:jiaochengji.com
教程集为您提供asp常用的安全过滤判断函数等资源,欢迎您收藏本站,我们将为您提供最新的asp常用的安全过滤判断函数资源

Function outHTML(str)
 Dim sTemp
 sTemp = str
 outHTML = ""
 If IsNull(sTemp) = True Then
  Exit Function
 End If
 sTemp = Replace(sTemp, "&", "&")
 sTemp = Replace(sTemp, "<", "&lt;")
 sTemp = Replace(sTemp, ">", "&gt;")
 sTemp = Replace(sTemp, Chr(34), "&quot;")
 sTemp = Replace(sTemp, Chr(10), "<br>")
 outHTML = sTemp
End Function

' ============================================
' 去除Html格式,用于从数据库中取出值填入输入框时
' 注意:value="?"这边一定要用双引号
' ============================================
Function inHTML(str)
 Dim sTemp
 sTemp = str
 inHTML = ""
 If IsNull(sTemp) = True Then
  Exit Function
 End If
 sTemp = Replace(sTemp, "&", "&amp;")
 sTemp = Replace(sTemp, "<", "&lt;")
 sTemp = Replace(sTemp, ">", "&gt;")
 sTemp = Replace(sTemp, Chr(34), "&quot;")
 inHTML = sTemp
End Function

' ============================================
' 检测上页是否从本站提交
' 返回:True,False
' ============================================
Function IsSelfRefer()
 Dim sHttp_Referer, sServer_Name
 sHttp_Referer = CStr(Request.ServerVariables("HTTP_REFERER"))
 sServer_Name = CStr(Request.ServerVariables("SERVER_NAME"))
 If Mid(sHttp_Referer, 8, Len(sServer_Name)) = sServer_Name Then
  IsSelfRefer = True
 Else
  IsSelfRefer = False
 End If
End Function

' ============================================
' 得到安全字符串,在查询中使用
' ============================================
Function Get_SafeStr(str)
 Get_SafeStr = Replace(Replace(Replace(Trim(str), "'", ""), Chr(34), ""), ";", "")
End Function

' ============================================
' 取实际字符长度
' ============================================
Function Get_TrueLen(str)
 Dim l, t, c, i
 l = Len(str)
 t = l
 For i = 1 To l
  c = Asc(Mid(str, i, 1))
  If c < 0 Then c = c 65536
  If c > 255 Then t = t 1
 Next
 Get_TrueLen = t
End Function

' ============================================
' 判断是否安全字符串,在注册登录等特殊字段中使用
' ============================================
Function IsSafeStr(str)
 Dim s_BadStr, n, i
 s_BadStr = "'  &<>?%,;:()`~!@#$^*{}[]| -=" & Chr(34) & Chr(9) & Chr(32)
 n = Len(s_BadStr)
 IsSafeStr = True
 For i = 1 To n
  If Instr(str, Mid(s_BadStr, i, 1)) > 0 Then
   IsSafeStr = False
   Exit Function
  End If
 Next
End Function

 

您可能感兴趣的文章:
asp常用的安全过滤判断函数
如何防止SQL注入
php防止sql注入函数(discuz)
PHP漏洞中的战争
asp防止js或sql注入的方法详解
php简单的参数过滤代码学习
php防范sql注入的一些代码收集
file_exists与is_file、is_dir的区别
php防止sql注入的方法总结
学习php的防SQL注入函数:mysql_real_escape_string

[关闭]
~ ~