<%

function HTMLEncode(fString)
    if not isnull(fString) then
        fString = replace(fString, ">", "&gt;")
        fString = replace(fString, "<", "&lt;")
        fString = Replace(fString, CHR(32), "&nbsp;")
        fString = Replace(fString, CHR(9), "&nbsp;")
        fString = Replace(fString, CHR(34), "&quot;")
        fString = Replace(fString, CHR(39), "&#39;")
        fString = Replace(fString, CHR(13), "")
        fString = Replace(fString, CHR(10) & CHR(10), "<P></P>")
        fString = Replace(fString, CHR(10), "<BR>")

        HTMLEncode = fString
    end if
end function
Function HTMLCode(fString)
	If Not IsNull(fString) then
	fString = replace(fString, "&gt;", ">")
	fString = replace(fString, "&lt;", "<")
	fString = Replace(fString,  "&nbsp;"," ")
	fString = Replace(fString, "&quot;", CHR(34))
	fString = Replace(fString, "&#39;", CHR(39))
	fString = Replace(fString, "<P></P> ",CHR(10) & CHR(10))
	fString = Replace(fString, "<BR> ", CHR(10))
	HTMLCode = fString
	End If
End Function

'防sql注入
Public function HX_Replace(str)
    if not isnull(str) and str<>"" then
	str	= Replace(str,"&","&amp;")	
	str = replace(str, ">", "&gt;")
	str = replace(str, "<", "&lt;")
	str = Replace(str, CHR(32), "&nbsp;")' 空格
	str = Replace(str, CHR(9), "&nbsp;")'  键盘的Tab键
	str = Replace(str, CHR(34), "&quot;")'  "
	str = Replace(str, CHR(39), "&#39;")'  '
	str = Replace(str, CHR(13), "")' 回车符
	str = Replace(str, "script", "&#115;cript")
	str = Replace(str, "＆#115;", "&#115;")' 字母S
	str = Replace(str, Chr(10), "<br>")
    HX_Replace = str
   end if
end function

'把数据库中的<br>转换为换行符。用于在文本框中显示。
Public function intobox(str)
   if not isnull(str) and str<>"" then
	str = Replace(str, "<br>",Chr(10) )
	str = Replace(str, "&nbsp;",Chr(32) )
    intobox = str
   end if
end function
	
'判断提交信息是否来自外部
Public Function ChkIsOuter()
	Dim server_v1,server_v2
	server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
	server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
	If Mid(server_v1,8,len(server_v2))<>server_v2 Then 
	response.Write("<script language=javascript>alert('请不要从外部数据!');window.close();</script>")
	response.end
	end if
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
' ============================================
' 得到安全字符串,在查询中使用
' ============================================
Function Get_SafeStr(str)
	Get_SafeStr = Replace(Replace(Replace(Trim(str), "'", ""), Chr(34), ""), ";", "")
End Function

%>