查看: 1819|回复: 0

几个常用函数.asp

[复制链接]
发表于 2005-5-9 00:29:55 | 显示全部楼层 |阅读模式
<>'获取用户真实IP函数<BR>Function GetIP()<BR>    GetIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")<BR>    If GetIP = "" Then GetIP = Request.ServerVariables("REMOTE_ADDR")<BR>End Function</P>
<><BR>'获取完整地址栏地址<BR>Function GetUrl()<BR>    GetUrl="<a href='http://"&amp;Request.ServerVariables("SERVER_N' target="_blank" >http://"&amp;Request.ServerVariables("SERVER_N</A> ... .ServerVariables("URL")<BR>    If Request.ServerVariables("QUERY_STRING")&lt;&gt;"" Then GetURL=GetUrl&amp;"?"&amp; Request.ServerVariables("QUERY_STRING")<BR>End Function</P>
<>'获取本页文件名<BR>Function SelfName()<BR>    SelfName = Mid(Request.ServerVariables("URL"),InstrRev(Request.ServerVariables("URL"),"/")+1)<BR>End Function</P>
<>'获取文件后缀名<BR>Function GetExt(filename)<BR>    GetExt = Mid(filename,InstrRev(filename,".")+1)<BR>End Function</P>
<><BR>'求字符串长度函数<BR>Function GetLength(str)<BR>    Dim i,length<BR>    For i = 1 to Len(str)<BR>        If Asc(Mid(str,i,1))&lt;0 or Asc(Mid(str,i,1))&gt;256 Then<BR>            length = length+2<BR>        Else<BR>            length = length+1<BR>        End If<BR>    Next<BR>    GetLength = length<BR>End Function</P>

<>'过滤不良字符<BR>Function ChkBadWords(fString)<BR>    Dim BadWords,bwords,i<BR>    BadWords = "我操|操你|操他|你妈的|他妈的|狗|杂种|屄|屌|王八|强奸|做爱|处女|泽民|***|法伦|洪志|法輪"<BR>    If Not(IsNull(BadWords) or IsNull(fString)) Then<BR>    bwords = Split(BadWords, "|")<BR>    For i = 0 to UBound(bwords)<BR>        fString = Replace(fString, bwords(i), string(Len(bwords(i)),"*"))<BR>    Next<BR>    ChkBadWords = fString<BR>    End If<BR>End Function</P>
<><BR>'防止外部提交<BR>Function ChkPost()<BR>    Dim URL1,URL2<BR>    ChkPost = False<BR>    URL1 = Cstr(Request.ServerVariables("HTTP_REFERER"))<BR>    URL2 = Cstr(Request.ServerVariables("SERVER_NAME"))<BR>    If Mid(URL1,8,Len(URL2))&lt;&gt;URL2 Then<BR>        ChkPost = False<BR>    Else<BR>        ChkPost = True<BR>    End If<BR>End Function</P>
<><BR>'过滤HTML字符函数,这个和我发的转义处理基本一样的。可以参考那个!<BR>Function HTMLEncode(fString)<BR>If Not IsNull(fString) And fString &lt;&gt; "" Then<BR>    fString = Replace(fString, "&gt;", "&amp;gt;")<BR>    fString = Replace(fString, "&lt;", "&amp;lt;")<BR>    fString = Replace(fString, Chr(32), "&amp;nbsp;")<BR>    fString = Replace(fString, Chr(9), "&amp;nbsp;&amp;nbsp;")<BR>    fString = Replace(fString, Chr(34), "&amp;quot;")<BR>    fString = Replace(fString, Chr(39), "&amp;#39;")<BR>    fString = Replace(fString, Chr(13), "")<BR>    fString = Replace(fString, Chr(10) &amp; Chr(10), "&lt;/P&gt;&lt&gt;")<BR>    fString = Replace(fString, Chr(10), "&lt;BR&gt;")<BR>    fString = Replace(fString, Chr(255), "&amp;nbsp;")<BR>    HTMLEncode = fString<BR>End If<BR>End Function</P>
<><BR>'清除HTML标记<BR>Function stripHTML(strHTML)<BR>    Dim objRegExp,strOutput<BR>    Set objRegExp = New Regexp<BR>    objRegExp.IgnoreCase = True<BR>    objRegExp.Global = True<BR>    objRegExp.Pattern = "&lt;.+?&gt;"<BR>    strOutput = objRegExp.Replace(strHTML,"")<BR>    strOutput = Replace(strOutput, "&lt;","&amp;lt;")<BR>    strOutput = Replace(strOutput, "&gt;","&amp;gt;")<BR>    stripHTML = strOutput<BR>    Set objRegExp = Nothing<BR>End Function</P>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条


关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖QQ客服返回顶部