常用ASP自定義函數全集(2)_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:解讀ASP常見錯誤類型大全
      ActiveServerPages,ASP0126(0x80004005)--找不到包含文件 MicrosoftOLEDBProviderforODBCDrivers(0x80040E21)--sql語句出錯(數據類型不匹配或表名(字段名)錯誤或表處于編輯狀態,或表不存在于conn打開的數據庫中) MicrosoftOLEDBProviderforODBCDrivers(0x800


      ''Email檢測
      function IsValidEmail(email)
      dim names, name, i, c
      IsValidEmail = true
      names = Split(email, "@")
      if UBound(names) <> 1 then
          IsValidEmail = false
          exit function
      end if
      for each name in names
          if Len(name) <= 0 then
            IsValidEmail = false
            exit function
          end if
          for i = 1 to Len(name)
            c = Lcase(Mid(name, i, 1))
            if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
              IsValidEmail = false
              exit function
            end if
          next
          if Left(name, 1) = "." or Right(name, 1) = "." then
             IsValidEmail = false
             exit function
          end if
      next
      if InStr(names(1), ".") <= 0 then
          IsValidEmail = false
          exit function
      end if
      i = Len(names(1)) - InStrRev(names(1), ".")
      if i <> 2 and i <> 3 then
          IsValidEmail = false
          exit function
      end if
      if InStr(email, "..") > 0 then
          IsValidEmail = false
      end if
      end function
      '--------------------------------
      '不允許外部提交數據的選擇
      Function ChkPost()
           dim HTTP_REFERER,SERVER_NAME
      dim server_v1,server_v2
      chkpost=false
           SERVER_NAME=CheckStr(Request.ServerVariables("SERVER_NAME"))
      HTTP_REFERER=CheckStr(Request.ServerVariables("HTTP_REFERER"))
      server_v1=Cstr(HTTP_REFERER)
      server_v2=Cstr(SERVER_NAME)
      if mid(server_v1,8,len(server_v2))<>server_v2 then
         chkpost=false
      else
         chkpost=true
      end if
      End Function
      '--------------------------------
      '構造上傳圖片文件名隨機數
      function MakedownName()
      dim fname
      randomize
      fname = now()
      fname = replace(fname,"-","")
      fname = replace(fname," ","")
      fname = replace(fname,":","")
      fname = replace(fname,"PM","")
      fname = replace(fname,"AM","")
      fname = replace(fname,"上午","")
      fname = replace(fname,"下午","")
      fname = int(fname) + int(((9-1+1)*Rnd + 1)*100000)   '6位
      MakedownName=fname
      end function
      '--------------------------------
      '獲取IP地址
      Function getIP()
           Dim strIPAddr
           If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
               strIPAddr = Request.ServerVariables("REMOTE_ADDR")
           ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
               strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
           ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
               strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
           Else
               strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
           End If
           getIP = Trim(Mid(strIPAddr, 1, 30))
      End Function
      '--------------------------------

      分享:ASP實現長文章手動分頁的代碼
      % setrecordset1=server.createobject(adodb.recordset) exec=SELECT*FROMnewswhereid=id recordset1.Openexec,conn,1,1 % tablewidth=85%border=0align=centercellpadding=3cellspacing=0 trtd ....... % IfRequest(page)=Then pageNum=0

      來源:模板無憂//所屬分類:ASP教程/更新時間:2010-04-10
      相關ASP教程