下面这些ASP函数在平时的网站制作中都是相当有用的,有必要学习一下,相当有必要!

‘获取用户真实IP函数
FunctionGetIP()
GetIP=Request.ServerVariables(“HTTP_X_FORWARDED_FOR”)
IfGetIP=””ThenGetIP=Request.ServerVariables(“REMOTE_ADDR”)
EndFunction

‘获取完整地址栏地址
FunctionGetUrl()
GetUrl=”http://”&Request.ServerVariables(“SERVER_NAME”)&Request.ServerVariables(“URL”)
IfRequest.ServerVariables(“QUERY_STRING”)<>“”ThenGetURL=GetUrl&”?”&Request.ServerVariables(“QUERY_STRING”)
EndFunction

‘获取本页文件名 From vcoo.me
FunctionSelfName()
SelfName=Mid(Request.ServerVariables(“URL”),InstrRev(Request.ServerVariables(“URL”),”/”) 1)
EndFunction

‘获取文件后缀名 From vcoo.me
FunctionGetExt(filename)
GetExt=Mid(filename,InstrRev(filename,”.”) 1)
EndFunction

‘求字符串长度函数 From vcoo.me
FunctionGetLength(str)
Dimi,length
Fori=1toLen(str)
IfAsc(Mid(str,i,1))<0orAsc(Mid(str,i,1))>256Then
length=length 2
Else
length=length 1
EndIf
Next
GetLength=length
EndFunction

‘过滤不良字符 From vcoo.me
FunctionChkBadWords(fString)
DimBadWords,bwords,i
BadWords=”我操%src=”/attachments/month_0711/%操你%src=”/attachments/month_0711/%操他%src=”/attachments/month_0711/%你妈的%src=”/attachments/month_0711/%他妈的%src=”/attachments/month_0711/%狗%src=”/attachments/month_0711/%杂种%src=”/attachments/month_0711/%屄%src=”/attachments/month_0711/%屌%src=”/attachments/month_0711/%王八%src=”/attachments/month_0711/%强奸%src=”/attachments/month_0711/%做爱%src=”/attachments/month_0711/%处女%src=”/attachments/month_0711/%泽民%src=”/attachments/month_0711/%法轮%src=”/attachments/month_0711/%法伦%src=”/attachments/month_0711/%洪志%src=”/attachments/month_0711/%法輪”
IfNot(IsNull(BadWords)orIsNull(fString))Then
bwords=Split(BadWords,”%src=”/attachments/month_0711/%”)
Fori=0toUBound(bwords)
fString=Replace(fString,bwords(i),string(Len(bwords(i)),”*”))
Next
ChkBadWords=fString
EndIf
EndFunction

‘防止外部提交 From vcoo.me
FunctionChkPost()
DimURL1,URL2
ChkPost=False
URL1=Cstr(Request.ServerVariables(“HTTP_REFERER”))
URL2=Cstr(Request.ServerVariables(“SERVER_NAME”))
IfMid(URL1,8,Len(URL2))<>URL2Then
ChkPost=False
Else
ChkPost=True
EndIf
EndFunction

‘过滤HTML字符函数 From vcoo.me
FunctionHTMLEncode(fString)
IfNotIsNull(fString)AndfString<>“”Then
fString=Replace(fString,”&”,”&”)
fString=Replace(fString,”>”,”>”)
fString=Replace(fString,”<","<")
fString=Replace(fString,Chr(32),” “)
fString=Replace(fString,Chr(9),” “)
fString=Replace(fString,Chr(34),”””)
fString=Replace(fString,Chr(39),”‘”)
fString=Replace(fString,Chr(13),””)
fString=Replace(fString,Chr(10)&Chr(10),”

“)
fString=Replace(fString,Chr(10),”
“)
fString=Replace(fString,Chr(255),” “)
HTMLEncode=fString
EndIf
EndFunction

‘清除HTML标记 From vcoo.me
FunctionstripHTML(strHTML)
DimobjRegExp,strOutput
SetobjRegExp=NewRegexp
objRegExp.IgnoreCase=True
objRegExp.Global=True
objRegExp.Pattern=”<. ?>“
strOutput=objRegExp.Replace(strHTML,””)
strOutput=Replace(strOutput,”<","<")
strOutput=Replace(strOutput,”>”,”>”)
stripHTML=strOutput
SetobjRegExp=Nothing
EndFunction

发表评论

/ 快捷键:Ctrl+Enter
加载中……