The Common Security filtering judgment function of ASP

Source: Internet
Author: User

Function outhtml (str)
 dim stemp
 stemp = str
 outhtml = "
 if IsNull (stemp) = Tru E Then
  exit Function
 end If
 stemp = Replace (Stemp, "&", "&")
 stemp = Replace (Stemp, "<", "&lt;")
 stemp = Replace (stemp, ">", "&gt;")
 stemp = Replace (Stemp, Chr (), &quot;)
 stemp = Replace (Stemp, Chr (), <br>)
 outhtml = stemp
End Function

' ============================================
' removes the HTML format for fetching values from the database when filling in the input box
' NOTE: value= '? This way, be sure to use double quotes
' ============================================
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 (), &quot;)
 inhtml = stemp
End Function

' ============================================
' Detect if the page is submitted from this site
' Back: 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

' ============================================
' Get a secure string to use in a query
' ============================================
Function get_safestr (str)
GET_SAFESTR = replace (replace (Trim (str), "'", ""), Chr (34), ""), ";"
End Function

' ============================================
' takes the actual character length
' ============================================
Function Get_truelen (str)
 dim L, T, C, I
 l = Len (str)
 t = L
 for i = 1 to l
&N Bsp; 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

' ============================================
' To determine if a secure string is used in special fields such as registration login
' ============================================
Function issafestr (str)
Dim s_badstr, N, I
S_badstr = "' &<>?%,;:() ' ~!@#$^*{}[]|+-= ' & Chr (+) & 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.