最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP动网早期一些比较常用的函数技巧

日期:02-21    来源:中国设计秀    作者:cnwebshow.com

<%wSP中国设计秀
' 判断提交是否來自外部wSP中国设计秀
Public Function ChkPost()wSP中国设计秀
    Dim server_v1,server_v2wSP中国设计秀
    Chkpost=False wSP中国设计秀
    server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))wSP中国设计秀
    server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))wSP中国设计秀
    If Mid(server_v1,8,len(server_v2))=server_v2 Then Chkpost=True wSP中国设计秀
End FunctionwSP中国设计秀
'系统分配随机密码wSP中国设计秀
Public Function Createpass()wSP中国设计秀
    Dim Ran,i,LengthNumwSP中国设计秀
    LengthNum=16wSP中国设计秀
    Createpass=""wSP中国设计秀
    For i=1 To LengthNumwSP中国设计秀
        RandomizewSP中国设计秀
        Ran = CInt(Rnd * 2)wSP中国设计秀
        RandomizewSP中国设计秀
        If Ran = 0 ThenwSP中国设计秀
            Ran = CInt(Rnd * 25) + 97wSP中国设计秀
            Createpass =Createpass& UCase(Chr(Ran))wSP中国设计秀
        ElseIf Ran = 1 ThenwSP中国设计秀
            Ran = CInt(Rnd * 9)wSP中国设计秀
            Createpass = Createpass & RanwSP中国设计秀
        ElseIf Ran = 2 ThenwSP中国设计秀
            Ran = CInt(Rnd * 25) + 97wSP中国设计秀
            Createpass =Createpass& Chr(Ran)wSP中国设计秀
        End IfwSP中国设计秀
    NextwSP中国设计秀
End FunctionwSP中国设计秀
'重写executewSP中国设计秀
Rem Function wSP中国设计秀
Public Function Execute(Command)wSP中国设计秀
    If Not IsObject(Conn) Then ConnectionDatabasewSP中国设计秀
    '检查权限,防止注入攻击wSP中国设计秀
    If InStr(LCase(Command),"dv_admin")>0 And Left(ScriptName,6)<> "admin_" Then wSP中国设计秀
        Response.Write SaveSQLLOG(Command,"")wSP中国设计秀
        Command=Replace(LCase(Command),"dv_admin","dv<i>"&Chr(95)&"</i>admin") wSP中国设计秀
    End If                wSP中国设计秀
    If IsDeBug = 0 Then wSP中国设计秀
        On Error Resume NextwSP中国设计秀
        Set Execute = Conn.Execute(Command)wSP中国设计秀
        If Err ThenwSP中国设计秀
            err.ClearwSP中国设计秀
            Set Conn = NothingwSP中国设计秀
            Response.Write SaveSQLLOG(Command,"查询数据的时候发现错误,请检查您的查询代码是否正确。<br>基于安全的理由,只显示本信息,要查看详细的错误信息,请修改您的程序文件conn.asp。把""Const IsDeBug = 0""改为:""Const IsDeBug = 1""")wSP中国设计秀
            Response.EndwSP中国设计秀
        End IfwSP中国设计秀
    ElsewSP中国设计秀
        'Response.Write command & "<br>"wSP中国设计秀
        Set Execute = Conn.Execute(Command)wSP中国设计秀
    End If    wSP中国设计秀
    SqlQueryNum = SqlQueryNum+1wSP中国设计秀
End FunctionwSP中国设计秀

'记录查询错误事件wSP中国设计秀
Public Function SaveSQLLOG(sCommand,message)wSP中国设计秀
    Dim lConnStr,lConn,ldb,SQL,RSwSP中国设计秀
    ldb = "data/DvSQLLOG.mdb"wSP中国设计秀
    lConnStr = "PRovider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(ldb)wSP中国设计秀
    Set lConn = Server.CreateObject("ADODB.Connection")wSP中国设计秀
    lConn.Open lConnStrwSP中国设计秀
    Set Rs = Server.CreateObject("adodb.recordset")wSP中国设计秀
    Sql="select * from dv_sql_log"wSP中国设计秀
    Rs.open sql,lconn,1,3wSP中国设计秀
    Rs.addnewwSP中国设计秀
    Rs("ScriptName")=ScriptNamewSP中国设计秀
    Rs("S_Info")=Left(sCommand,255)wSP中国设计秀
    Rs("ip")=UserTrueIPwSP中国设计秀
    Rs.updatewSP中国设计秀
    Rs.closewSP中国设计秀
    lConn.Execute(SQL)wSP中国设计秀
    lConn.ClosewSP中国设计秀
    Set lConn = Nothing wSP中国设计秀
    SaveSQLLOG = messagewSP中国设计秀
End FunctionwSP中国设计秀

'IP来源wSP中国设计秀
Public Function address(sip)wSP中国设计秀
    Dim aConnStr,aConn,adbwSP中国设计秀
    Dim str1,str2,str3,str4wSP中国设计秀
    Dim  numwSP中国设计秀
    Dim country,citywSP中国设计秀
    Dim irs,SQLwSP中国设计秀
    If IsNumeric(Left(sip,2)) ThenwSP中国设计秀
        If sip="127.0.0.1" Then sip="192.168.0.1"wSP中国设计秀
        str1=Left(sip,InStr(sip,".")-1)wSP中国设计秀
        sip=mid(sip,instr(sip,".")+1)wSP中国设计秀
        str2=Left(sip,instr(sip,".")-1)wSP中国设计秀
        sip=Mid(sip,InStr(sip,".")+1)wSP中国设计秀
        str3=Left(sip,instr(sip,".")-1)wSP中国设计秀
        str4=Mid(sip,instr(sip,".")+1)wSP中国设计秀
        If isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 ThenwSP中国设计秀
        Else        wSP中国设计秀
            num=CLng(str1)*16777216+CLng(str2)*65536+CLng(str3)*256+CLng(str4)-1wSP中国设计秀
            adb = "data/ipaddress.mdb"wSP中国设计秀
            aConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(adb)wSP中国设计秀
            Set AConn = Server.CreateObject("ADODB.Connection")wSP中国设计秀
            aConn.Open aConnStrwSP中国设计秀

            sql="select top 1 country,city from dv_address where ip1 <="&num&" and ip2 >="&num&""wSP中国设计秀
            Set irs=aConn.execute(sql)wSP中国设计秀
            If irs.EOF And irs.bof ThenwSP中国设计秀
                country="亚洲"wSP中国设计秀
                city=""wSP中国设计秀
            ElsewSP中国设计秀
                country=irs(0)wSP中国设计秀
                city=irs(1)wSP中国设计秀
            End IfwSP中国设计秀
            Set irs=NothingwSP中国设计秀
            Set aConn = Nothing wSP中国设计秀
            SqlQueryNum = SqlQueryNum+1wSP中国设计秀
        End IfwSP中国设计秀
        address=country&citywSP中国设计秀
    Else wSP中国设计秀
        address="未知"wSP中国设计秀
    End IfwSP中国设计秀
End FunctionwSP中国设计秀
    wSP中国设计秀
'用于用户发布的各种信息过滤,带脏话过滤wSP中国设计秀
Public Function HTMLEncode(fString)wSP中国设计秀
    If Not IsNull(fString) ThenwSP中国设计秀
        fString = replace(fString, ">", ">")wSP中国设计秀
        fString = replace(fString, "<", "<")wSP中国设计秀
        fString = Replace(fString, CHR(32), " ")        ' wSP中国设计秀
        fString = Replace(fString, CHR(9), " ")            ' wSP中国设计秀
        fString = Replace(fString, CHR(34), """)wSP中国设计秀
        fString = Replace(fString, CHR(39), "'")    '过滤单引号wSP中国设计秀
        fString = Replace(fString, CHR(13), "")wSP中国设计秀
        fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")wSP中国设计秀
        fString = Replace(fString, CHR(10), "<BR> ")wSP中国设计秀
        fString=ChkBadwords(fString)wSP中国设计秀
        HTMLEncode = fStringwSP中国设计秀
    End IfwSP中国设计秀
End FunctionwSP中国设计秀
'用于论坛本身的过滤,不带脏话过滤wSP中国设计秀
Public Function iHTMLEncode(fString)wSP中国设计秀
    If Not IsNull(fString) ThenwSP中国设计秀
        fString = replace(fString, ">", ">")wSP中国设计秀
        fString = replace(fString, "<", "<")wSP中国设计秀
        fString = Replace(fString, CHR(32), " ")wSP中国设计秀
        fString = Replace(fString, CHR(9), " ")wSP中国设计秀
        fString = Replace(fString, CHR(34), """)wSP中国设计秀
        fString = Replace(fString, CHR(39), "'")wSP中国设计秀
        fString = Replace(fString, CHR(13), "")wSP中国设计秀
        fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")wSP中国设计秀
        fString = Replace(fString, CHR(10), "<BR> ")wSP中国设计秀
        iHTMLEncode = fStringwSP中国设计秀
    End IfwSP中国设计秀
End FunctionwSP中国设计秀
Public Function strLength(str)wSP中国设计秀
    If isNull(str) or Str = "" ThenwSP中国设计秀
        StrLength = 0wSP中国设计秀
        Exit FunctionwSP中国设计秀
    End IfwSP中国设计秀
    Dim WINNT_CHINESEwSP中国设计秀
    WINNT_CHINESE=(len("例子")=2)wSP中国设计秀
    If WINNT_CHINESE ThenwSP中国设计秀
        Dim l,t,cwSP中国设计秀
        Dim iwSP中国设计秀
        l=len(str)wSP中国设计秀
        t=lwSP中国设计秀
        For i=1 To lwSP中国设计秀
            c=asc(mid(str,i,1))wSP中国设计秀
            If c<0 Then c=c+65536wSP中国设计秀
            If c>255 Then t=t+1wSP中国设计秀
        NextwSP中国设计秀
        strLength=twSP中国设计秀
    Else wSP中国设计秀
        strLength=len(str)wSP中国设计秀
    End IfwSP中国设计秀
End FunctionwSP中国设计秀
Public Function ChkBadwords(Str)wSP中国设计秀
    If IsNull(Str) Then Exit FunctionwSP中国设计秀
    Dim iwSP中国设计秀
    For i = 0 To Ubound(Badwords)wSP中国设计秀
        If i > UBound(rBadword) ThenwSP中国设计秀
            Str = Replace(Str,Badwords(i),"*")wSP中国设计秀
        ElsewSP中国设计秀
            Str = Replace(Str,Badwords(i),rBadword(i))wSP中国设计秀
        End IfwSP中国设计秀
    NextwSP中国设计秀
    ChkBadwords = StrwSP中国设计秀
End FunctionwSP中国设计秀
Public Function Checkstr(Str)wSP中国设计秀
    If Isnull(Str) ThenwSP中国设计秀
        CheckStr = ""wSP中国设计秀
        Exit Function wSP中国设计秀
    End IfwSP中国设计秀
    CheckStr = Replace(Str,"'","''")wSP中国设计秀
End FunctionwSP中国设计秀
'取得带端口的URL,推荐使用wSP中国设计秀
Property Get Get_ScriptNameUrl()wSP中国设计秀
    If request.servervariables("SERVER_PORT")="80" ThenwSP中国设计秀
        Get_ScriptNameUrl="http://" & request.servervariables("server_name")&replace(lcase(request.servervariables("script_name")),ScriptName,"")wSP中国设计秀
    ElsewSP中国设计秀
        Get_ScriptNameUrl="http://" & request.servervariables("server_name")&":"&request.servervariables("SERVER_PORT")&replace(lcase(request.servervariables("script_name")),ScriptName,"")wSP中国设计秀
    End IfwSP中国设计秀
End PropertywSP中国设计秀

'检查Email地址有效性wSP中国设计秀
function IsValidEmail(email)wSP中国设计秀
dim names, name, i, cwSP中国设计秀
IsValidEmail = truewSP中国设计秀
names = Split(email, "@")wSP中国设计秀
if UBound(names) <> 1 thenwSP中国设计秀
   IsValidEmail = falsewSP中国设计秀
   exit functionwSP中国设计秀
end ifwSP中国设计秀
for each name in nameswSP中国设计秀
   if Len(name) <= 0 thenwSP中国设计秀
     IsValidEmail = falsewSP中国设计秀
     exit functionwSP中国设计秀
   end ifwSP中国设计秀
   for i = 1 to Len(name)wSP中国设计秀
     c = Lcase(Mid(name, i, 1))wSP中国设计秀
     if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) thenwSP中国设计秀
       IsValidEmail = falsewSP中国设计秀
       exit functionwSP中国设计秀
     end ifwSP中国设计秀
   nextwSP中国设计秀
   if Left(name, 1) = "." or Right(name, 1) = "." thenwSP中国设计秀
      IsValidEmail = falsewSP中国设计秀
      exit functionwSP中国设计秀
   end ifwSP中国设计秀
nextwSP中国设计秀
if InStr(names(1), ".") <= 0 thenwSP中国设计秀
   IsValidEmail = falsewSP中国设计秀
   exit functionwSP中国设计秀
end ifwSP中国设计秀
i = Len(names(1)) - InStrRev(names(1), ".")wSP中国设计秀
if i <> 2 and i <> 3 thenwSP中国设计秀
   IsValidEmail = falsewSP中国设计秀
   exit functionwSP中国设计秀
end ifwSP中国设计秀
if InStr(email, "..") > 0 thenwSP中国设计秀
   IsValidEmail = falsewSP中国设计秀
end ifwSP中国设计秀

end functionwSP中国设计秀

function strLength(str)wSP中国设计秀
       ON ERROR RESUME NEXTwSP中国设计秀
       dim WINNT_CHINESEwSP中国设计秀
       WINNT_CHINESE    = (len("论坛")=2)wSP中国设计秀
       if WINNT_CHINESE thenwSP中国设计秀
          dim l,t,cwSP中国设计秀
          dim iwSP中国设计秀
          l=len(str)wSP中国设计秀
          t=lwSP中国设计秀
          for i=1 to lwSP中国设计秀
             c=asc(mid(str,i,1))wSP中国设计秀
             if c<0 then c=c+65536wSP中国设计秀
             if c>255 thenwSP中国设计秀
                t=t+1wSP中国设计秀
             end ifwSP中国设计秀
          nextwSP中国设计秀
          strLength=twSP中国设计秀
       else wSP中国设计秀
          strLength=len(str)wSP中国设计秀
       end ifwSP中国设计秀
       if err.number<>0 then err.clearwSP中国设计秀
end functionwSP中国设计秀

function cutStr(str,strlen)wSP中国设计秀
    dim l,t,cwSP中国设计秀
    l=len(str)wSP中国设计秀
    t=0wSP中国设计秀
    for i=1 to lwSP中国设计秀
    c=Abs(Asc(Mid(str,i,1)))wSP中国设计秀
    if c>255 thenwSP中国设计秀
    t=t+2wSP中国设计秀
    elsewSP中国设计秀
    t=t+1wSP中国设计秀
    end ifwSP中国设计秀
    if t>=strlen thenwSP中国设计秀
    cutStr=left(str,i)&"..."wSP中国设计秀
    exit forwSP中国设计秀
    elsewSP中国设计秀
    cutStr=strwSP中国设计秀
    end ifwSP中国设计秀
    nextwSP中国设计秀
    cutStr=replace(cutStr,chr(10),"")wSP中国设计秀
end functionwSP中国设计秀

Function fixjs(Str)wSP中国设计秀
    If Str <>"" ThenwSP中国设计秀
        str = replace(str,"", "")wSP中国设计秀
        Str = replace(str, chr(34), """")wSP中国设计秀
        Str = replace(str, chr(39),"'")wSP中国设计秀
        Str = Replace(str, chr(13), "n")wSP中国设计秀
        Str = Replace(str, chr(10), "r")wSP中国设计秀
        str = replace(str,"'", "'")wSP中国设计秀
    End IfwSP中国设计秀
    fixjs=StrwSP中国设计秀
End FunctionwSP中国设计秀
Function enfixjs(Str)wSP中国设计秀
    If Str <>"" ThenwSP中国设计秀
        Str = replace(str,"'", "'")wSP中国设计秀
        Str = replace(str,"""" , chr(34))wSP中国设计秀
        Str = replace(str, "'",chr(39))wSP中国设计秀
        Str = Replace(str, "r", chr(10))wSP中国设计秀
        Str = Replace(str, "n", chr(13))wSP中国设计秀
        Str = replace(str,"", "")wSP中国设计秀
    End IfwSP中国设计秀
    enfixjs=StrwSP中国设计秀
End FunctionwSP中国设计秀

wSP中国设计秀
Class Cls_BrowserwSP中国设计秀
    Public Browser,version ,platformwSP中国设计秀
    Private Sub Class_Initialize()wSP中国设计秀
        Browser="unknown"wSP中国设计秀
        version="unknown"wSP中国设计秀
        platform="unknown"wSP中国设计秀
        Dim AgentwSP中国设计秀
        Agent=Request.ServerVariables("HTTP_USER_AGENT")wSP中国设计秀
        Agent=Split(Agent,";")wSP中国设计秀
        If InStr(Agent(1),"MSIE")>0 ThenwSP中国设计秀
            Browser="Microsoft Internet Explorer "wSP中国设计秀
            version=Trim(Left(Replace(Agent(1),"MSIE",""),6))wSP中国设计秀
        ElseIf InStr(Agent(4),"Netscape")>0 Then wSP中国设计秀
            Browser="Netscape "wSP中国设计秀
            Dim tmpstrwSP中国设计秀
            tmpstr=Split(Agent(4),"/")wSP中国设计秀
            version=tmpstr(UBound(tmpstr))wSP中国设计秀
        End IfwSP中国设计秀
        If InStr(Agent(2),"NT 5.2")>0 ThenwSP中国设计秀
            platform="Windows 2003"wSP中国设计秀
        ElseIf InStr(Agent(2),"NT 5.1")>0 ThenwSP中国设计秀
            platform="Windows xp"wSP中国设计秀
        ElseIf InStr(Agent(2),"NT 5.0")>0 ThenwSP中国设计秀
            platform="Windows 2000"wSP中国设计秀
        ElseIf InStr(Agent(2),"9x")>0 ThenwSP中国设计秀
            platform="Windows ME"wSP中国设计秀
        ElseIf InStr(Agent(2),"98")>0 ThenwSP中国设计秀
            platform="Windows 98"wSP中国设计秀
        ElseIf InStr(Agent(2),"95")>0 ThenwSP中国设计秀
            platform="Windows 95"wSP中国设计秀
        End If    wSP中国设计秀
        '记录未知AgentwSP中国设计秀
        If Browser="unknown" or version="unknown" or platform="unknown" ThenwSP中国设计秀
            Agent=Dvbbs.checkStr(Request.ServerVariables("HTTP_USER_AGENT"))wSP中国设计秀
            Dim lConnStr,lConn,ldbwSP中国设计秀
            ldb = "data/DvSQLLOG.mdb"wSP中国设计秀
            lConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(ldb)wSP中国设计秀
            Set lConn = Server.CreateObject("ADODB.Connection")wSP中国设计秀
            lConn.Open lConnStrwSP中国设计秀
            lConn.Execute("insert into [Agent](UserAgent)Values('" & Agent & "')")wSP中国设计秀
            lConn.ClosewSP中国设计秀
            Set lConn = Nothing wSP中国设计秀
        End IfwSP中国设计秀
    End Sub wSP中国设计秀
End ClasswSP中国设计秀

%>wSP中国设计秀

本文引用地址:/bc/article_46286.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明