<%

Rem 过滤SQL非法字符
function checkFFSQLStr(str)
	if isnull(str) then
		checkFFSQLStr = ""
		exit function 
	end if
	str=replace(str," ","")
	str=replace(str,";","")
	str=replace(str,"'","''")
	checkFFSQLStr=str
end function

Rem 判断数字是否整形
function isChkInteger(para)
       on error resume next
       dim str
       dim l,i
       if isNUll(para) then 
          isChkInteger=false
          exit function
       end if
       str=cstr(para)
       if trim(str)="" then
          isChkInteger=false
          exit function
       end if
       l=len(str)
       for i=1 to l
           if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
              isChkInteger=false 
              exit function
           end if
       next
       isChkInteger=true
       if err.number<>0 then err.clear
end function

'-----------------------截取字符串函数
function cutStr(str,strlen)

'--------增加容错环节
'------------原始字符串检查
	If str = "" Then
	cutStr = "cutStr函数异常：字符串为空"
	exit function
	End If
'------------来源长度检查
	If  strlen = "" Then
	cutStr = "cutStr函数异常：长度未指定"
	exit function
	End If	

	If  CInt(strlen) = 0 Then
	cutStr = "cutStr函数异常：长度为0"
	exit function
	End If	
'----------检测来源字符长度
	dim l,t,c
	l=len(str)
	t=0
'----------循环截取字符
	for i=1 to l
	c=Abs(Asc(Mid(str,i,1)))
	'------判断是否汉字
	if c>255 then
	t=t+2
	else
	t=t+1
	end If
	'------判断是否到达指定长度
	if t>=strlen then
	cutStr=left(str,i)&".."
	exit for
	else
	cutStr=str
	end if
	next
	cutStr=replace(cutStr,chr(10),"")
end function



function tohtml(byval str1)
tempstr=str1
tempstr=replace(tempstr,"<br>"," ")
tempstr=replace(tempstr,"&","&amp;")
tempstr=replace(tempstr,">","&gt;")
tempstr=replace(tempstr,"<","&lt;")
tohtml=tempstr
end Function


'--------HTML 加密函数
function htmlecode(byval str1)
 Str=str1
 Str = Replace(Str,Chr(13)&Chr(10),"<br>", 1, -1, 1)	'回车+换行
 Str = Replace(Str,Chr(13),"<br>", 1, -1, 1)			'回车
 Str = Replace(Str,Chr(10),"<br>", 1, -1, 1)			'换行
 Str = Replace(Str,"<br><br>","<br>", 1, -1, 1)			'去除连续
 Str = Replace(Str,Chr(0),"", 1, -1, 1)
 Str = Replace(Str, "object", "&#111;bject", 1, -1, 0)	'SQL单词过滤
 Str = Replace(Str, "OBJECT", "&#079;BJECT", 1, -1, 0)
 Str = Replace(Str, "Object", "&#079;bject", 1, -1, 0)
 Str = Replace(Str, "object", "&#079;bject", 1, -1, 1)
 Str = Replace(Str, "applet", "&#097;pplet", 1, -1, 0)
 Str = Replace(Str, "APPLET", "&#065;PPLET", 1, -1, 0)
 Str = Replace(Str, "Applet", "&#065;pplet", 1, -1, 0)
 Str = Replace(Str, "applet", "&#065;pplet", 1, -1, 1)
 Str = Replace(Str, "server", "&#115;erver", 1, -1, 0) 'server 字符
 Str = Replace(Str, "=", "&#061;", 1, -1, 1)
 Str = Replace(Str, "'", "''", 1, -1, 1)
 Str = Replace(Str, "select", "sel&#101;ct", 1, -1, 1)
 Str = Replace(Str, "execute", "&#101xecute", 1, -1, 1)
 Str = Replace(Str, "exec", "&#101xec", 1, -1, 1)
 Str = Replace(Str, "join", "jo&#105;n", 1, -1, 1)
 Str = Replace(Str, "union", "un&#105;on", 1, -1, 1)
 Str = Replace(Str, "where", "wh&#101;re", 1, -1, 1)
 Str = Replace(Str, "insert", "ins&#101;rt", 1, -1, 1)
 Str = Replace(Str, "delete", "del&#101;te", 1, -1, 1)
 Str = Replace(Str, "update", "up&#100;ate", 1, -1, 1)
 Str = Replace(Str, "like", "lik&#101;", 1, -1, 1)
 Str = Replace(Str, "drop", "dro&#112;", 1, -1, 1)
 Str = Replace(Str, "create", "cr&#101;ate", 1, -1, 1)
 Str = Replace(Str, "rename", "ren&#097;me", 1, -1, 1)
 Str = Replace(Str, "count", "co&#117;nt", 1, -1, 1)
 Str = Replace(Str, "chr", "c&#104;r", 1, -1, 1)
 Str = Replace(Str, "mid", "m&#105;d", 1, -1, 1)
 Str = Replace(Str, "truncate", "trunc&#097;te", 1, -1, 1)
 Str = Replace(Str, "nchar", "nch&#097;r", 1, -1, 1)
 Str = Replace(Str, "char", "ch&#097;r", 1, -1, 1)
 Str = Replace(Str, "alter", "alt&#101;r", 1, -1, 1)
 Str = Replace(Str, "cast", "ca&#115;t", 1, -1, 1)
 Str = Replace(Str, "exists", "e&#120;ists", 1, -1, 1)
 Str = Replace(Str, "[", "&#091;")
 Str = Replace(Str, "]", "&#093;")
 Str = replace(Str,"&","&amp;")
 Str = replace(Str,">","&gt;")
 Str = replace(Str,"<","&lt;")
 htmlecode = Str
end function

'-------HTML 解释函数
function forhtml(str1)
tempstr=str1
tempstr=replace(tempstr,"&quot;","""")
tempstr=replace(tempstr,"&amp;","&")
tempstr=replace(tempstr,"&gt;",">")
tempstr=replace(tempstr,"&lt;","<")
forhtml=tempstr
end function

function htmltotext(byval nr)
''过滤html字符的
if not isnull(nr) then
pa=""
strContent=nr

Set regex = New RegExp 
regEx.Global = True

regEx.IgnoreCase = False ' 设置是否区分大小写。<BR>

'去掉换行
regEx.Pattern = "\n"
strContent = regEx.Replace(strContent,"")

regEx.Pattern = "<[a-zA-Z]+([ ]|[^\n>]|[%$#@!'])*>"
strContent = regEx.Replace(strContent,"")
regEx.Pattern = "</[a-zA-Z]+>"
strContent = regEx.Replace(strContent,"")
regEx.Pattern = "[ ]+"
strContent = regEx.Replace(strContent," ")

strContent=replace(strContent,"&nbsp;","")

if len(strContent)>1000 then
strContent=left(strContent,1000) & "......"
end if
end if
htmltotext=strContent

end function

function HTMLEncode2(fString)
	fString = Replace(fString, CHR(13), "")
	fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
	fString = Replace(fString, CHR(10), "<BR>")
	HTMLEncode2 = fString
end function

function nosql(str)
if not isnull(str) then
str=trim(str)
str=replace(str,";","&#59;")		'分号
str=replace(str,"'","&#39;")		'单引号
str=replace(str,"""","&quot;")		'双引号
str=replace(str,"chr(9)","&nbsp;")	'空格
str=replace(str,"chr(10)","<br>")	'回车
str=replace(str,"chr(13)","<br>")	'回车
str=replace(str,"chr(32)","&nbsp;")	'空格
str=replace(str,"chr(34)","&quot;")	'双引号
str=replace(str,"chr(39)","&#39;")	'单引号
str=Replace(str, "script", "&#115cript")'jscript
str=replace(str,"<","&lt;")	        '左<
str=replace(str,">","&gt;")	        '右>
str=replace(str,"(","&#40;")	        '左(
str=replace(str,")","&#41;")	        '右)
str=replace(str,"--","&#45;&#45;")	'SQL注释符
nosql=str
end if
end function

%>
<%
function isshuzi(str,er)
'----------检测是否为数字类型
If Not IsNumeric(str) Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数  [ "& er &" ] 非数字类型');history.go(-1);</script>"
response.End
End If

'----------检测是否含有小数点
If  Instr(LCase(Str),".") Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 含有非法符号.');history.go(-1);</script>"
response.End
End If

'----------检测是否含有-
If  cint(Str)  < 0   Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 数值异常：小于零-');history.go(-1);</script>"
response.End
End If

'----------检测是否含有+
If  Instr(LCase(Str),"+")  Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 含有非法符号+');history.go(-1);</script>"
response.End
End If

'----------检测是否含有/
If  Instr(LCase(Str),"/")  Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 含有非法符号/');history.go(-1);</script>"
response.End
End If

'----------检测是否含有*
If  Instr(LCase(Str),"*")  Then
response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 含有非法符号*');history.go(-1);</script>"
response.End
End If



'----------检测是否超出范围
If str > 65535 Then

response.Write "<script language='javascript'>alert('参数错误\n\n参数：[ "& er &" ] 超出范围');history.go(-1);</script>"
response.End
End If

'---------检测通过,返回数值
isshuzi = str
end Function

%>