ATHENA's profile闲人勿入BlogListsGuestbookMore Tools Help

Blog


    生成xbm格式的验证码


    on error resume next
    dim i
    dim countdata
    countdata="1234567890"
    dim rou,chkcode,chklen
    chkcode=""
    chklen = 4
    randomize
    for i=1 to 4
       rou = int(rnd*10)
       chkcode = chkcode + cstr(rou)
    next

    dim strDigits
    strDigits = Array(_
             "0","0x3c","0x66","0x66","0x66","0x66","0x66","0x66","0x66","0x66","0x3c",_
             "1","0x30","0x38","0x30","0x30","0x30","0x30","0x30","0x30","0x30","0x30",_
             "2","0x3c","0x66","0x60","0x60","0x30","0x18","0x0c","0x06","0x06","0x7e",_
             "3","0x3c","0x66","0x60","0x60","0x38","0x60","0x60","0x60","0x66","0x3c",_
             "4","0x30","0x30","0x38","0x38","0x34","0x34","0x32","0x7e","0x30","0x78",_
             "5","0x7e","0x06","0x06","0x06","0x3e","0x60","0x60","0x60","0x66","0x3c",_
             "6","0x38","0x0c","0x06","0x06","0x3e","0x66","0x66","0x66","0x66","0x3c",_
             "7","0x7e","0x66","0x60","0x60","0x30","0x30","0x18","0x18","0x0c","0x0c",_
             "8","0x3c","0x66","0x66","0x66","0x3c","0x66","0x66","0x66","0x66","0x3c",_
             "9","0x3c","0x66","0x66","0x66","0x66","0x7c","0x60","0x60","0x30","0x1c")

    dim iCharWidth,iCharHeight,theBit,theNum,iRow,k,theOffset
    dim imageStr
    imageStr = ""

    iCharWidth = 8
    iCharHeight= 10*1
    Response.ContentType ="image/x-xbitmap"
    Response.Expires =0
    Response.Write "#define counter_width "&iCharWidth*chklen&chr(13) & chr(10)
    Response.Write "#define counter_height "&iCharHeight&chr(13) & chr(10)
    Response.Write "static unsigned char counter_bits[]={"
    for iRow=0 to iCharHeight-1
       for i=1 to chklen
          theBit=mid(chkcode,i,1)
          k=0
          do while k<ubound(strDigits)
              if strDigits(k) = theBit then exit do
              k=k+iCharHeight+1
          loop
          if k>=ubound(strDigits) then k=0
          theOffset = k + 1
          imageStr = imageStr + (strDigits(theOffset+iRow))&","
       next
    next

    imageStr = left(imageStr,(len(imageStr)-1))
    Response.Write imageStr

    Response.Write "};"
    session("chkCode") = chkcode

    VerifyCode gif验证码生成技术

    <%
    Class Fly38_VerifyCode
            Public GlobalColorTable(), LocalColorTable()
            Public TransparentColorIndex, UseTransparency
            Public GIF89a
            Public Comment

            Private FGroundColorIndex, BGroundColorIndex
            Private Image
            Private GlobalColorTableSize, GlobalColorTableFlag, LocalColorTableSize, LocalColorTableFlag
            Private Width_, Height_
            Private LeftPosition, TopPosition
            Private Bits, ColorResolution, CodeSize
            Private PixelAspectRatio
            Private SortFlag, InterlaceFlag
            Private Seperator, GraphicControl, EndOfImage
            Private Reserved

            Private Font
            Private Letter(19)

            Private Sub Class_Initialize()
                      Image = ""
       
                      GIF89a = False
      
                      ReDim GlobalColorTable(256)
                      GlobalColorTableSize = 7
                      GlobalColorTableFlag = True
      
                      GlobalColorTable(2) = RGB(255, 0, 0)
                      GlobalColorTable(3) = RGB(0, 255, 0)
                      GlobalColorTable(4) = RGB(0, 0, 255)
                      GlobalColorTable(5) = RGB(255, 255, 0)
                      GlobalColorTable(6) = RGB(0, 255, 255)
                      GlobalColorTable(7) = RGB(255, 0, 255)
      
                      ReDim LocalColorTable(0)
                      LocalColorTableSize = 0
                      LocalColorTableFlag = False
      
                      ColorResolution = 7
                      Bits   = 7
                      CodeSize  = 7
      
                      BGroundColorIndex = 0
                      FGroundColorIndex = 1
                      TransparentColorIndex = 0
                      UseTransparency  = False
      
                      LeftPosition = 0
                      TopPosition  = 0
                      Width_   = 20
                      Height_   = 20
      
                      Clear
      
                      PixelAspectRatio = 0
                      SortFlag   = False
                      InterlaceFlag  = False
                      Seperator   = Asc(",")
                      GraphicControl  = Asc("!")
                      EndOfImage   = Asc(";")
      
                      Comment = ""
      
                      Reserved = 0
      
                      Set Font = Server.CreateObject("Scripting.Dictionary")

                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00001111100000"
                      Letter(2)  = "00011111110000"
                      Letter(3)  = "00111000111000"
                      Letter(4)  = "00110000011100"
                      Letter(5)  = "01110000001100"
                      Letter(6)  = "01100000001110"
                      Letter(7)  = "01100000001110"
                      Letter(8)  = "11100000001110"
                      Letter(9)  = "11000000001110"
                      Letter(10) = "11000000001110"
                      Letter(11) = "11100000001110"
                      Letter(12) = "11100000001100"
                      Letter(13) = "11100000001100"
                      Letter(14) = "01100000001100"
                      Letter(15) = "01110000011100"
                      Letter(15) = "00111000011000"
                      Letter(16) = "00011111110000"
                      Letter(17) = "00001111100000"
                      Letter(18) = "00000000000000"
                      Font.Add "0", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00000001110000"
                      Letter(2)  = "00000001110000"
                      Letter(3)  = "00000011100000"
                      Letter(4)  = "00000011000000"
                      Letter(5)  = "00000011000000"
                      Letter(6)  = "00000011000000"
                      Letter(7)  = "00000111000000"
                      Letter(8)  = "00000111000000"
                      Letter(9)  = "00000111000000"
                      Letter(10) = "00000110000000"
                      Letter(11) = "00000110000000"
                      Letter(12) = "00000110000000"
                      Letter(13) = "00000110000000"
                      Letter(14) = "00000110000000"
                      Letter(15) = "00000110000000"
                      Letter(15) = "00000110000000"
                      Letter(16) = "00000110000000"
                      Letter(17) = "00000010000000"
                      Letter(18) = "00000000000000"
                      Font.Add "1", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00001111110000"
                      Letter(2)  = "00011111111000"
                      Letter(3)  = "00111000011100"
                      Letter(4)  = "01110000011100"
                      Letter(5)  = "01110000011000"
                      Letter(6)  = "01100000011000"
                      Letter(7)  = "00000000111000"
                      Letter(8)  = "00000001110000"
                      Letter(9)  = "00000001110000"
                      Letter(10) = "00000011000000"
                      Letter(11) = "00000111000000"
                      Letter(12) = "00001110000000"
                      Letter(13) = "00011000000000"
                      Letter(14) = "00011000000000"
                      Letter(15) = "00110000011100"
                      Letter(16) = "01101111111100"
                      Letter(17) = "01111111111110"
                      Letter(18) = "01111100000000"
                      Letter(19) = "00000000000000"
                      Font.Add "2", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00001111111000"
                      Letter(2)  = "00111111111000"
                      Letter(3)  = "01110000111100"
                      Letter(4)  = "01100000011000"
                      Letter(5)  = "01000000111000"
                      Letter(6)  = "00000000111000"
                      Letter(7)  = "00000001110000"
                      Letter(8)  = "00000011000000"
                      Letter(9)  = "00000111110000"
                      Letter(10) = "00000100111000"
                      Letter(11) = "00000000011100"
                      Letter(12) = "00000000011100"
                      Letter(13) = "00000000011100"
                      Letter(14) = "00000000011100"
                      Letter(15) = "00000000011000"
                      Letter(16) = "11100000111000"
                      Letter(17) = "11111111110000"
                      Letter(18) = "01111111100000"
                      Letter(19) = "00000000000000"
                      Font.Add "3", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00000000111000"
                      Letter(2)  = "00000001111000"
                      Letter(3)  = "00000011100000"
                      Letter(4)  = "00000111011100"
                      Letter(5)  = "00001110011100"
                      Letter(6)  = "00001100011000"
                      Letter(7)  = "00011000111000"
                      Letter(8)  = "00111000110000"
                      Letter(9)  = "01110000110000"
                      Letter(10) = "01100000110000"
                      Letter(11) = "01100000110000"
                      Letter(12) = "11000111111110"
                      Letter(13) = "11111111111100"
                      Letter(14) = "11111111100000"
                      Letter(15) = "11100001100000"
                      Letter(16) = "00000001110000"
                      Letter(17) = "00000000110000"
                      Letter(18) = "00000000110000"
                      Letter(19) = "00000000100000"
                      Font.Add "4", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00001100000100"
                      Letter(2)  = "00011111111110"
                      Letter(3)  = "00011111111100"
                      Letter(4)  = "00011110000000"
                      Letter(5)  = "00011000000000"
                      Letter(6)  = "00111000000000"
                      Letter(7)  = "00111000000000"
                      Letter(8)  = "00111111110000"
                      Letter(9)  = "00111111111000"
                      Letter(10) = "00000000011000"
                      Letter(11) = "00000000011000"
                      Letter(12) = "00000000011000"
                      Letter(13) = "00000000011000"
                      Letter(14) = "00000000011000"
                      Letter(15) = "00000000011000"
                      Letter(16) = "00000001111000"
                      Letter(17) = "01111111110000"
                      Letter(18) = "00111111000000"
                      Letter(19) = "00000000100000"
                      Font.Add "5", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00000011110000"
                      Letter(2)  = "00000111100000"
                      Letter(3)  = "00001110000000"
                      Letter(4)  = "00011100000000"
                      Letter(5)  = "00111000000000"
                      Letter(6)  = "00110000000000"
                      Letter(7)  = "00110000000000"
                      Letter(8)  = "01111111110000"
                      Letter(9)  = "01111111111000"
                      Letter(10) = "01110000011100"
                      Letter(11) = "01100000001100"
                      Letter(12) = "01100000001100"
                      Letter(13) = "01100000001100"
                      Letter(14) = "01100000001100"
                      Letter(15) = "01110000011100"
                      Letter(16) = "00110000011100"
                      Letter(17) = "00111111111000"
                      Letter(18) = "00011111110000"
                      Letter(19) = "00000000000000"
                      Font.Add "6", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00100111111110"
                      Letter(2)  = "01111111111100"
                      Letter(3)  = "01111110011100"
                      Letter(4)  = "00000000011000"
                      Letter(5)  = "00000000111000"
                      Letter(6)  = "00000000110000"
                      Letter(7)  = "00000000110000"
                      Letter(8)  = "00000000110000"
                      Letter(9)  = "00000001110000"
                      Letter(10) = "00000001100000"
                      Letter(11) = "00000001100000"
                      Letter(12) = "00000001100000"
                      Letter(13) = "00000001100000"
                      Letter(14) = "00000011100000"
                      Letter(15) = "00000011100000"
                      Letter(16) = "00000011100000"
                      Letter(17) = "00000001000000"
                      Letter(18) = "00000001000000"
                      Letter(19) = "00000000000000"
                      Font.Add "7", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00001111110000"
                      Letter(2)  = "00011111111000"
                      Letter(3)  = "00111000011000"
                      Letter(4)  = "00110000011000"
                      Letter(5)  = "01110000011100"
                      Letter(6)  = "01110000011000"
                      Letter(7)  = "00110000011000"
                      Letter(8)  = "00111101111000"
                      Letter(9)  = "00011111111000"
                      Letter(10) = "00111000111100"
                      Letter(11) = "01110000001100"
                      Letter(12) = "01110000001100"
                      Letter(13) = "01100000001110"
                      Letter(14) = "01100000001100"
                      Letter(15) = "01100000001100"
                      Letter(16) = "01110000011100"
                      Letter(17) = "00111111111100"
                      Letter(18) = "00011111110000"
                      Letter(19) = "00000000000000"
                      Font.Add "8", Letter
      
                      Letter(0)  = "00000000000000"
                      Letter(1)  = "00011111110000"
                      Letter(2)  = "00111111111000"
                      Letter(3)  = "01110000111000"
                      Letter(4)  = "01110000011100"
                      Letter(5)  = "01100000001100"
                      Letter(6)  = "01100000001100"
                      Letter(7)  = "01100000001100"
                      Letter(8)  = "01100000001100"
                      Letter(9)  = "01110000011100"
                      Letter(10) = "00111111111100"
                      Letter(11) = "00011111111100"
                      Letter(12) = "00000000011000"
                      Letter(13) = "00000000011000"
                      Letter(14) = "00000000111000"
                      Letter(15) = "00000001110000"
                      Letter(16) = "00000011100000"
                      Letter(17) = "00000111000000"
                      Letter(18) = "00011110000000"
                      Letter(19) = "00000000000000"
                      Font.Add "9", Letter
            End Sub
    Private Sub Class_Terminate()
                      Font.RemoveAll
                      Set Font = Nothing
            End Sub

            Public Property Get Width()
                      Width = Width_
            End Property

            Public Property Get Height()
                      Height = Height_
            End Property

            Public Property Get Version()
                      Version = "NetRube VerifyCode Class 1.0 Build 20041225"
            End Property

            Public Property Let BGroundColor(ByVal Color)
                      GlobalColorTable(0) = MakeColor(Color)
                      BGroundColorIndex = 0
            End Property

            Public Property Let FGroundColor(ByVal Color)
                      GlobalColorTable(1) = MakeColor(Color)
                      FGroundColorIndex = 1
            End Property

            Public Property Get Pixel(ByVal PX, ByVal PY)
                      If (PX > 0 And PX <= Width_) And (PY > 0 And PY <= Height_) Then
                               Pixel = AscB(MidB(Image, (Width_ * (PY - 1)) + PX, 1))
                      Else
                               Pixel = 0
                      End If
            End Property

            Public Property Let Pixel(ByVal PX, ByVal PY, PValue)
                      Dim Offset
      
                      PX  = Int(PX)
                      PY  = Int(PY)
                      PValue = Int(PValue)
      
                      Offset = Width_ * (PY - 1)
      
                      If (PX > 0 And PX <= Width_) And (PY > 0 And PY <= Height_) Then
                               Image = LeftB(Image, Offset + (PX - 1)) & ChrB(PValue) & RightB(Image, LenB(Image) - (Offset + PX))
                      End If
            End Property

            Public Sub Clear()
                      Image = String(Width_ * (Height_ + 1) / 2, ChrB(BGroundColorIndex) & ChrB(BGroundColorIndex))
            End Sub

            Public Sub Resize(ByVal NewWidth, ByVal NewHeight, RPreserve)
                      Dim OldImage, OldWidth, OldHeight
                      Dim CopyWidth, CopyHeight
                      Dim X, Y
      
                      If RPreserve Then
                               OldImage = Image
                               OldWidth = Width_
                               OldHeight = Height_
                      End If
      
                      Width_ = NewWidth
                      Height_ = NewHeight
      
                      Clear
      
                      If RPreserve Then
                               If NewWidth > OldWidth Then CopyWidth = OldWidth Else CopyWidth = NewWidth
                               If NewHeight > OldHeight Then CopyHeight = OldHeight Else CopyHeight = NewHeight
       
                               Width_ = NewWidth
                               Height_ = NewHeight
       
                               For Y = 1 To CopyHeight
                                        For X = 1 To CopyWidth
                                                 Pixel(X, Y) = AscB(MidB(OldImage, (OldWidth * (Y - 1)) + X, 1))
                                        Next
                               Next
                      End If
            End Sub

            Private Function ShiftLeft(SLValue, SLBits)
                      ShiftLeft = SLValue * (2 ^ SLBits)
            End Function

            Private Function ShiftRight(SRValue, SRBits)
                      ShiftRight = Int(SRValue / (2 ^ SRBits))
            End Function

            Private Function Low(LValue)
                      Low = LValue And &HFF
            End Function

            Private Function High(HValue)
                      High = ShiftRight(HValue, 8)
            End Function

            Private Function Blue(BValue)
                      Blue = Low(ShiftRight(BValue, 16))
            End Function

            Private Function Green(GValue)
                      Green = Low(ShiftRight(GValue, 8))
            End Function

            Private Function Red(RValue)
                      Red = Low(RValue)
            End Function

            Private Function MakeColor(MCValue)
                      MakeColor = CLng("&H" & Right(MCValue, 2) & Mid(MCValue, 4, 2) & Mid(MCValue, 2, 2))
            End Function

            Private Function GetWord(GWValue)
                      GetWord = ShiftLeft(AscB(RightB(GWValue, 1)), 8) Or AscB(LeftB(GWValue, 1))
            End Function

            Private Function MakeWord(MWValue)
                      MakeWord = ChrB(Low(MWValue)) & ChrB(High(MWValue))
            End Function

            Private Function MakeByte(MBValue)
                      MakeByte = ChrB(Low(MBValue))
            End Function

            Private Function UncompressedData()
                      Dim ClearCode, ChunkMax, EndOfStream
                      Dim UDData, UD, U
      
                      UncompressedData = ""
      
                      ClearCode   = 2 ^ Bits
                      ChunkMax   = 2 ^ Bits - 2
                      EndOfStream   = ClearCode + 1
      
                      UDData    = ""
      
                      For U = 1 To LenB(Image) Step ChunkMax
                               UDData = UDData & MidB(Image, U, ChunkMax) & ChrB(ClearCode)
                      Next
      
                      For U = 1 To LenB(UDData) Step &HFF
                               UD     = MidB(UDData, U, &HFF)
                               UncompressedData = UncompressedData & MakeByte(LenB(UD)) & UD
                      Next
      
                      UncompressedData = UncompressedData & MakeByte(&H00)
                      UncompressedData = UncompressedData & MakeByte(EndOfStream)
            End Function

            Private Function GetGColorTable()
                      Dim GGCT
      
                      GetGColorTable = ""
      
                      For GGCT = 0 To UBound(GlobalColorTable) - 1
                               GetGColorTable = GetGColorTable & MakeByte(Red(GlobalColorTable(GGCT)))
                               GetGColorTable = GetGColorTable & MakeByte(Green(GlobalColorTable(GGCT)))
                               GetGColorTable = GetGColorTable & MakeByte(Blue(GlobalColorTable(GGCT)))
                      Next
            End Function

            Private Function GetLColorTable()
                      Dim GLCT

                      GetLColorTable = ""
      
                      For GLCT = 0 To UBound(LocalColorTable) - 1
                               GetLColorTable = GetLColorTable & MakeByte(Red(LocalColorTable(GLCT)))
                               GetLColorTable = GetLColorTable & MakeByte(Green(LocalColorTable(GLCT)))
                               GetLColorTable = GetLColorTable & MakeByte(Blue(LocalColorTable(GLCT)))
                      Next
            End Function

            Private Function GlobalDescriptor()
                      GlobalDescriptor = 0
      
                      If GlobalColorTableFlag Then GlobalDescriptor = GlobalDescriptor Or ShiftLeft(1, 7)
                      GlobalDescriptor = GlobalDescriptor Or ShiftLeft(ColorResolution, 7)
                      If SortFlag Then GlobalDescriptor = GlobalDescriptor Or ShiftLeft(1, 3)
                      GlobalDescriptor = GlobalDescriptor Or GlobalColorTableSize
            End Function

            Private Function LocalDescriptor()
                      LocalDescriptor = 0
      
                      If LocalColorTableFlag Then LocalDescriptor = LocalDescriptor Or ShiftLeft(1, 7)
                      If InterlaceFlag Then LocalDescriptor = LocalDescriptor Or ShiftLeft(1, 6)
                      If SortFlag Then LocalDescriptor = LocallDescriptor Or ShiftLeft(1, 5)
                      LocalDescriptor = LocalDescriptor Or ShiftLeft(Reserved, 3)
                      LocalDescriptor = LocalDescriptor Or LocalColorTableSize
            End Function

            Private Property Get ImageData()
                      Dim Text, I
      
                      ImageData = GIFHeader
                      ImageData = ImageData & MakeWord(Width_)
                      ImageData = ImageData & MakeWord(Height_)
                      ImageData = ImageData & MakeByte(GlobalDescriptor)
                      ImageData = ImageData & MakeByte(BGroundColorIndex)
                      ImageData = ImageData & MakeByte(PixelAspectRatio)
                      ImageData = ImageData & GetGColorTable
      
                      If GIF89a Then
                               If UseTransparency Then
                                        ImageData = ImageData & MakeByte(GraphicControl)
                                        ImageData = ImageData & MakeByte(&HF9)
                                        ImageData = ImageData & MakeByte(&H04)
                                        ImageData = ImageData & MakeByte(&H01)
                                        ImageData = ImageData & MakeByte(&H00)
                                        ImageData = ImageData & MakeByte(TransparentColorIndex)
                                        ImageData = ImageData & MakeByte(&H00)
                               End If
       
                               If Comment <> "" Then
                                        ImageData = ImageData & MakeByte(GraphicControl)
                                        ImageData = ImageData & MakeByte(&HFE)
                                        Text = Left(Comment, &HFF)
                                        ImageData = ImageData & MakeByte(Len(Text))
                                        For I = 1 To Len(Text)
                                                 ImageData = ImageData & MakeByte(Asc(Mid(Text, I, 1)))
                                        Next
                                        ImageData = ImageData & MakeByte(&H00)
                               End If
                      End If
      
                      ImageData = ImageData & MakeByte(Seperator)
                      ImageData = ImageData & MakeWord(LeftPosition)
                      ImageData = ImageData & MakeWord(TopPosition)
                      ImageData = ImageData & MakeWord(Width_)
                      ImageData = ImageData & MakeWord(Height_)
                      ImageData = ImageData & MakeByte(LocalDescriptor)
                      ImageData = ImageData & MakeByte(CodeSize)
                      ImageData = ImageData & UncompressedData
                      ImageData = ImageData & MakeByte(&H00)
                      ImageData = ImageData & MakeByte(EndOfImage)
            End Property

            Public Sub ImgWrite()
                      Response.ContentType = "image/gif"
                      Response.BinaryWrite ImageData
            End Sub

            Private Function GIFHeader()
                      GIFHeader = ""
                      GIFHeader = GIFHeader & ChrB(Asc("G"))
                      GIFHeader = GIFHeader & ChrB(Asc("I"))
                      GIFHeader = GIFHeader & ChrB(Asc("F"))
                      GIFHeader = GIFHeader & ChrB(Asc("8"))
                      If GIF89a Then
                            GIFHeader = GIFHeader & ChrB(Asc("9"))
                    Else
                            GIFHeader = GIFHeader & ChrB(Asc("7"))
                    End If
                      GIFHeader = GIFHeader & ChrB(Asc("a"))
            End Function

            Public Sub VerifyCode(Text, VCColor)
                      Dim I1, I2, I3
                      Dim VCX, VCY, VCIndex
      
                      Resize 14 * Len(Text) + 10, UBound(Letter) + 10, False
      
                      Randomize
                      VCX = Int(Rnd * 10)
                      VCY = Int(Rnd * (Height_ - UBound(Letter)))
      
                      For I1 = 0 To UBound(Letter) - 1
                               For I2 = 1 To Len(Text)
                                        For I3 = 1 To Len(Font(Mid(Text, I2, 1))(I1))
                                                 VCIndex = CLng(Mid(Font(Mid(Text, I2, 1))(I1), I3, 1))
         
                                                 If VCIndex <> 0 Then
                                                          If VCColor Then
                                                                   Randomize
                                                                   VCIndex = Int(Rnd * 7)
                                                          End If
          
                                                          Pixel(VCX + ((I2 - 1) * Len(Letter(0))) + I3, VCY + I1) = VCIndex
                                                 End If
                                        Next
                               Next
                      Next
            End Sub

            Public Sub Noises(Amount, NColor)
                      Dim NI, NIndex
       
                      For NI = 1 To Amount
                               NIndex = 1
       
                               If NColor Then
                                        Randomize
                                        NIndex = Int(Rnd * 7)
                               End If
       
                               Pixel(Int(Rnd * Width_), Int(Rnd * Height_)) = NIndex
                      Next
            End Sub

    End Class
    %>

    用法

    <%
    Dim GBL_CookieName
    GBL_CookieName = "gbl_codename" '指定一个想对本站的cookie


    Call ShowCode(GBL_CookieName & Request("CodeName"))   'request("CodeName")指定一个相对验证码的cookie
    '验证码
    Sub ShowCode(ShowCodeName)
            Set img = New fly38_VerifyCode
            Randomize
            Dim code
            code = Int(Rnd * 9000 + 1000)
            Session(ShowCodeName) = code
            img.BGroundColor = "#FFFFFF" ' 图片背景颜色
            img.FGroundColor = "#FF0000" ' 前景(文本)颜色
            Call img.VerifyCode(code, False)  ' 处理验证码,第二个参数为是否显示彩色文本
            Call img.Noises(100, True)   ' 添加杂点,第一个参数为杂点数量,第二个参数为是否显示彩色杂点
            img.ImgWrite ' 输出图片
    End Sub
    %>

    无组件生成GIF验证码

     

    <%
    Option Explicit ' 显示声明

    Class Com_GifCode_Class
    '''''''''''''''''''''''''''''''''''''''''''''
    ' Author: Layen support@ssaw.net 84815733(QQ)
    ' Thanks: Laomi, Laomiao, NetRube
    ' 2006-01-02
    '''''''''''''''''''''''''''''''''''''''''''''
    Public Noisy, Count, Width, Height, Angle, Offset, Border

    Private Graph(), Margin(3)

    Private Sub Class_Initialize()
    Randomize
    Noisy = 16 ' 干扰点出现的概率
    Count = 4 ' 字符数量
    Width = 80 ' 图片宽度
    Height = 20 ' 图片高度
    Angle = 2 ' 角度随机变化量
    Offset = 20 ' 偏移随机变化量
    Border = 1 ' 边框大小
    End Sub

    Public Function Create()

    Const cCharSet = "123456789"

    Dim i, x, y

    Dim vValidCode : vValidCode = ""
    Dim vIndex

    ReDim Graph(Width-1, Height-1)

    For i = 0 To Count - 1
    vIndex = Int(Rnd * Len(cCharSet))
    vValidCode = vValidCode + Mid(cCharSet, vIndex+1 , 1)
    SetDraw vIndex, i
    Next

    Create = vValidCode

    End Function

    Sub SetDot(pX, pY)
    If pX * (Width-pX-1) >= 0 And pY * (Height-pY-1) >= 0 Then
    Graph(pX, pY) = 1
    End If
    End Sub

    Public Sub SetDraw(pIndex, pNumber)

    ' 字符数据
    Dim DotData(8)
    DotData(0) = Array(30, 15, 50, 1, 50, 100)
    DotData(1) = Array(1 ,34 ,30 ,1 ,71, 1, 100, 34, 1, 100, 93, 100, 100, 86)
    DotData(2) = Array(1, 1, 100, 1, 42, 42, 100, 70, 50, 100, 1, 70)
    DotData(3) = Array(100, 73, 6, 73, 75, 6, 75, 100)
    DotData(4) = Array(100, 1, 1, 1, 1, 50, 50, 35, 100, 55, 100, 80, 50, 100, 1, 95)
    DotData(5) = Array(100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, 100, 60, 70, 50, 30, 50, 1, 60)
    DotData(6) = Array(6, 26, 6, 6, 100, 6, 53, 100)
    DotData(7) = Array(100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100, 80, 70, 100, 30, 100, 1, 80, 1, 70, 100, 30)
    DotData(8) = Array(1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30, 1, 1, 20, 1, 40, 30, 50, 70, 50, 100, 40)

    Dim vExtent : vExtent = Width / Count
    Margin(0) = Border + vExtent * (Rnd * Offset) / 100 + Margin(1)
    Margin(1) = vExtent * (pNumber + 1) - Border - vExtent * (Rnd * Offset) / 100
    Margin(2) = Border + Height * (Rnd * Offset) / 100
    Margin(3) = Height - Border - Height * (Rnd * Offset) / 100

    Dim vStartX, vEndX, vStartY, vEndY
    Dim vWidth, vHeight, vDX, vDY, vDeltaT

    Dim vAngle, vLength

    vWidth = Int(Margin(1) - Margin(0))

    vHeight = Int(Margin(3) - Margin(2))

    ' 起始坐标
    vStartX = Int((DotData(pIndex)(0)-1) * vWidth / 100)

    vStartY = Int((DotData(pIndex)(1)-1) * vHeight / 100)

    Dim i, j
    For i = 1 To UBound(DotData(pIndex), 1)/2

    If DotData(pIndex)(2*i-2) <> 0 And DotData(pIndex)(2*i) <> 0 Then

    ' 终点坐标
    vEndX = (DotData(pIndex)(2*i)-1) * vWidth / 100

    vEndY = (DotData(pIndex)(2*i+1)-1) * vHeight / 100

    ' 横向差距
    vDX = vEndX - vStartX
    ' 纵向差距
    vDY = vEndY - vStartY

    ' 倾斜角度
    If vDX = 0 Then
    vAngle = Sgn(vDY) * 3.14/2
    Else
    vAngle = Atn(vDY / vDX)
    End If

    ' 两坐标距离
    If Sin(vAngle) = 0 Then
    vLength = vDX
    Else
    vLength = vDY / Sin(vAngle)
    End If

    ' 随机转动角度
    vAngle = vAngle + (Rnd - 0.5) * 2 * Angle * 3.14 * 2 / 100

    vDX = Int(Cos(vAngle) * vLength)

    vDY = Int(Sin(vAngle) * vLength)

    If Abs(vDX) > Abs(vDY) Then vDeltaT = Abs(vDX) Else vDeltaT = Abs(vDY)

    For j = 1 To vDeltaT
    SetDot Margin(0) + vStartX + j * vDX / vDeltaT, Margin(2) + vStartY + j * vDY / vDeltaT
    Next

    vStartX = vStartX + vDX

    vStartY = vStartY + vDY
    End If
    Next
    End Sub

    Public Sub Output()

    Response.Expires = -9999
    Response.AddHeader "pragma", "no-cache"
    Response.AddHeader "cache-ctrol", "no-cache"
    Response.ContentType = "image/gif"

    ' 文件类型
    Response.BinaryWrite ChrB(Asc("G")) & ChrB(Asc("I")) & ChrB(Asc("F"))
    ' 版本信息
    Response.BinaryWrite ChrB(Asc("8")) & ChrB(Asc("9")) & ChrB(Asc("a"))
    ' 逻辑屏幕宽度
    Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)
    ' 逻辑屏幕高度
    Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)

    Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(0)
    ' 全局颜色列表
    Response.BinaryWrite ChrB(255) & ChrB(255) & ChrB(255)

    Response.BinaryWrite ChrB(0) & ChrB(85) & ChrB(255)

    ' 图象标识符
    Response.BinaryWrite ChrB(Asc(","))

    Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
    ' 图象宽度
    Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)
    ' 图象高度
    Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)

    Response.BinaryWrite ChrB(0) & ChrB(7) & ChrB(255)

    Dim x, y, i : i = 0
    For y = 0 To Height - 1
    For x = 0 To Width - 1
    If Rnd < Noisy / 100 Then
    Response.BinaryWrite ChrB(1-Graph(x, y))
    Else
    If x * (x-Width) = 0 Or y * (y-Height) = 0 Then
    Response.BinaryWrite ChrB(Graph(x, y))
    Else
    If Graph(x-1, y) = 1 Or Graph(x, y) Or Graph(x, y-1) = 1 Then
    Response.BinaryWrite ChrB(1)
    Else
    Response.BinaryWrite ChrB(0)
    End If
    End If
    End If
    If (y * Width + x + 1) Mod 126 = 0 Then
    Response.BinaryWrite ChrB(128)
    i = i + 1
    End If
    If (y * Width + x + i + 1) Mod 255 = 0 Then
    If (Width*Height - y * Width - x - 1) > 255 Then
    Response.BinaryWrite ChrB(255)
    Else
    Response.BinaryWrite ChrB(Width * Height Mod 255)
    End If
    End If
    Next
    Next
    Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(129) & ChrB(0) & ChrB(59)
    End Sub
    End Class

    Dim mCode
    Set mCode = New Com_GifCode_Class
    Session("GetCode") = mCode.Create()
    mCode.Output()
    Set mCode = Nothing
    %>

    正在使用的ASP验证码

    vColorData设定颜色
     
    <%
    Call Com_CreatValidCode()
    Sub Com_CreatValidCode() ' 禁止缓存
    Response.Expires = -9999
    Response.AddHeader "Pragma","no-cache"
    Response.AddHeader "cache-ctrol","no-cache"
    Response.ContentType = "Image/BMP"
    Randomize
    Dim i, ii, iii
    Const cOdds = 10
    Const cAmount = 36 ' 文字数量
    Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ' 颜色的数据(字符,背景)
    Dim vColorData(2)
    a=Rnd * 200
    b=Rnd * 200
    c=Rnd * 200
    vColorData(0) = ChrB(a) & ChrB(b) & ChrB(c) '
    'vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) ' 蓝0,绿0,红0(黑色)0的位置颜色
    vColorData(1) = ChrB(255) & ChrB(255) & ChrB(255) ' 蓝250,绿236,红211(白色) 1的位置颜色 ' 随机产生字符
    Dim vCode(4), vCodes
    For i = 0 To 3
    vCode(i) = Int(Rnd * cAmount)
    vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
    Next
    session("code") = vCodes '记录入Session ' 字符的数据
    Dim vNumberData(36)
    vNumberData(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
    vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
    vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
    vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
    vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
    vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
    vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
    vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
    vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
    vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
    vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
    vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
    vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
    vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
    vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
    vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
    vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
    vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
    vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
    vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
    vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
    vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
    vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
    vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
    vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
    vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
    vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
    vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
    vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
    vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
    vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
    vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
    vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
    vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
    vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
    vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"' 输出图像文件头
    Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
      ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) &_
      ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) &_
      ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
    ' 输出图像信息头
    Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) &_
      ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) &_
      ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
      ChrB(0) & ChrB(0)
    For i = 9 To 0 Step -1  ' 历经所有行
      For ii = 0 To 3  ' 历经所有字
       For iii = 1 To 10 ' 历经所有像素
        ' 逐行、逐字、逐像素地输出图像数据
        If Rnd * 99 + 1 < cOdds Then ' 随机生成杂点
         Response.BinaryWrite vColorData(0)
        Else
         Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
        End If
       Next
      Next
    Next
    End Sub
    %>

    ASP 生成 彩色 可变长 数字 验证码程序

    本验证码生成程序特点如下:

    一、彩色;

    二、BMP 图像色深为 16 位,生成的图片体积更小;(4位长的验证码只有几百字节)

    三、长度可自定义;(1位至25位可固定设置,也可以自己改成动态)

    四、背景杂色深度可自定义;

    具体请看代码

    注:代码中并没有针对动网的 设置验证码 Session 的地方。想用的朋友自己根据需要改一下,位置就在代码中出现  Session("Num") 的那一行,改成自己需要的名称就可以了。

    下面是代码部分:

    Option Explicit
    Response.Expires = 0
    Response.AddHeader "Pragma","no-cache"
    Response.AddHeader "cache-ctrol","no-cache"
    Response.ContentType = "Image/BMP"
    Randomize Timer

    Dim Text_Data(9),Text_Len,Int_Temp(),I,j,k,Int_Temp2

    ''***** 参数配置区 *****

    Text_Len = 4 ''验证码长度(支持1-25位)

    ''**********************

    ReDim Int_Temp( Text_Len - 1 )

    Text_Data(0)  = "00000000000001111000001100110000110111000011011100001100110000111011000011101100001100110000011110000000000000"
    Text_Data(1)  = "00000000000000011000000011100000111110000000011000000001100000000110000000011000000001100000000110000000000000"
    Text_Data(2)  = "00000000000001111000001100110000110011000000001100000001100000001100000001100000001100000000111111000000000000"
    Text_Data(3)  = "00000000000001111000001100110000110011000000001100000011100000000011000011001100001100110000011110000000000000"
    Text_Data(4)  = "00000000000001100000000110000000011011000001101100000110110000110011000011111110000000110000000011000000000000"
    Text_Data(5)  = "00000000000011111100001100000000110000000011000000001111100000000011000000001100000001100000111100000000000000"
    Text_Data(6)  = "00000000000000111000000011000000011000000011111000001100110000110011000011001100001100110000011110000000000000"
    Text_Data(7)  = "00000000000011111100000000110000000110000000011000000011000000001100000001100000000110000000011000000000000000"
    Text_Data(8)  = "00000000000001111000001100110000110011000011101100000111100000110111000011001100001100110000011110000000000000"
    Text_Data(9)  = "00000000000001111000001100110000110011000011001100001100110000011111000000011000000011000000011100000000000000"

    ''下面随机生成各位验证码
    Session("Num") = ""
    For I = 0 To Text_Len - 1
       Int_Temp(I) = Int(Rnd * 10)
       Session("Num") = Session("Num") + Mid("0123456789",Int_Temp(I)+1,1)
    Next

    ''下面输出文件头部分
    Int_Temp2 = (Text_Len - 1) \ 4 * 220 + ((Text_Len - 1) / 4 - (Text_Len - 1) \ 4 * 4) * 44
    Response.BinaryWrite ChrB(&H42) & ChrB(&H4D)
    Response.BinaryWrite ChrB(((Int_Temp2 + 206) / 256 - (Int_Temp2 + 206) \ 256) * 256) & ChrB((Int_Temp2 + 206) \ 256)   ''特殊位
    Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H76) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H28) & ChrB(0) & ChrB(0) & ChrB(0)
    Response.BinaryWrite ChrB(Text_Len * 10)   ''特殊位
    Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HB) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H1) & ChrB(0) & ChrB(&H4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
    Response.BinaryWrite ChrB(((Int_Temp2 + 88) / 256 - (Int_Temp2 + 88) \ 256) * 256) & ChrB((Int_Temp2 + 88) \ 256)   ''特殊位

    Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(16) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(16) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(0) & ChrB(&H80) & ChrB(0)
    Response.BinaryWrite ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(0) & ChrB(&H80) & ChrB(&H80) & ChrB(&H80) & ChrB(0) & ChrB(&HC0) & ChrB(&HC0) & ChrB(&HC0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0) & ChrB(0) & ChrB(&HFF) & ChrB(&HFF) & ChrB(&HFF) & ChrB(0)

    ''下面输出图片数据
    For i = 10 to 0 Step -1
       For j = 0 to Text_Len - 1
          For k = 1 to 9 Step 2
             If Mid(Text_Data(Int_Temp(j)) ,  i * 10 + k , 1) = "0" Then Int_Temp2 = Get_BackColor() * 16 Else Int_Temp2 = Get_ForeColor() * 16
             If Mid(Text_Data(Int_Temp(j)) ,  i * 10 + k + 1 , 1) = "0" Then Int_Temp2 = Int_Temp2 + Get_BackColor() Else Int_Temp2 = Int_Temp2 + Get_ForeColor()
             Response.BinaryWrite ChrB(Int_Temp2)
          Next
       Next
       Int_Temp2 = (Text_Len / 4 - Text_Len \ 4) * 4
       Select Case Int_Temp2
       Case 1
          Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0)
       Case 2
          Response.BinaryWrite ChrB(0) & ChrB(0)
       Case 3
          Response.BinaryWrite ChrB(0)
       End Select
    Next

    Function Get_BackColor()
    ''得到一个背景色
    If Int(Rnd * 30) = 0 Then ''注:此处的 Rnd * 30 是决定背景杂色的多少,值越大,则杂色越少,图片越容易看清楚
       Get_BackColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
    Else
       Get_BackColor = CInt(Mid("081515151515",Int(Rnd * 6) * 2 + 1,2))
    End If
    End Function

    Function Get_ForeColor()
    ''得到一个前景色
    Get_ForeColor = CInt(Mid("00021209",Int(Rnd * 4) * 2 + 1,2))
    End Function

    图片数据写入SQL

    这个不怎么了解,只能照抄了,很久没做这方面的东西都忘了。不知道能不能直接EXECUTE,有时间再看看。
     

    '取得客户端送出的数据字节大小
    frmsize=Request.TotalBytes
     
    '以二进制方式读取数据
    frmData=Request.BinaryRead(frmsize)
     
    '去掉实际数据前、后的边界字符串行
    bnCrLf=ChrB(13)&ChrB(10)
    divider=leftB(frmdata,CLng(InstrB(frmdata,bnCrLf))-1)
    dataStart=InstrB(frmData,bnCrLf&bncrlf)+4
    dataEnd=InstrB(datastart+1,frmData,divider)-dataStart
     
    '读出图象数据
    myData=Midb(frmdata,dataStart,dataEnd)
     
    '将图象数据存入数据库
    strSQL="SELECT * FROM tblImages"
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.open strSQL,conn,1,3
    rs.addnew
    rs("picData").AppendChunk myData
    rs.Update
    counts=rs.recordCount+1
    rs.close
    conn.close
     

    strSQL="SELECT picData FROM tblImages WHERE id=" & sID
    Set rs=Server.CreateObject("ADODB.Recordset")
    rs.Open strSQL,conn,1,1
    Response.ContentType="image/*"
    dataSize=rs(0).actualSize
    Response.BinaryWrite rs(0).getChunk(dataSize)

    rs.Close
    conn.Close

    二进制编码转换函数

    据说第一个比第二个快30倍,我看应该没有,不过第二个实在很烂。
     
    第一个:
    Function bytes2BSTR(binstr)
    Dim BytesStream,StringReturn
    Set BytesStream = CreateObject("ADODB.Stream")
    With BytesStream
     .Type = 2
     .Open
    .WriteText binstr
    .Position = 0
    .Charset = "GB2312"
    .Position = 2
    StringReturn = .ReadText
    .close
    End With
    Set BytesStream = Nothing
    bytes2BSTR = StringReturn
    End Function
     
     
    第二个:
    Function bytes2BSTR(vIn)
    dim strReturn
    dim i1,ThisCharCode,NextCharCode
    strReturn = ""
    For i1 = 1 To LenB(vIn)
    ThisCharCode = AscB(MidB(vIn,i1,1))
    If ThisCharCode < &H80 Then
    strReturn = strReturn & Chr(ThisCharCode)
    Else
    NextCharCode = AscB(MidB(vIn,i1+1,1))
    strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
    i1 = i1 + 1
    End If
    Next
    bytes2BSTR = strReturn
    End Function

    URL解码函数

    server.URLEncode的逆操作函数,好象只能转英文和数字。
     
     
    Function URLDecode(enStr) 
      dim deStr
      dim c,i,v
      deStr=""
      for i=1 to len(enStr)
          c=Mid(enStr,i,1)
          if c="%" then
              v=eval("&h"+Mid(enStr,i+1,2))
              if v<128 then
                  deStr=deStr&chr(v)
                  i=i+2
              else
                  if isvalidhex(mid(enstr,i,3)) then
                      if isvalidhex(mid(enstr,i+3,3)) then
                          v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
                          deStr=deStr&chr(v)
                          i=i+5
                      else
                          v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
                          deStr=deStr&chr(v)
                          i=i+3 
                      end if 
                  else 
                      destr=destr&c
                  end if
              end if
          else
              if c="+" then
                  deStr=deStr&" "
              else
                  deStr=deStr&c
              end if
          end if
      next
      URLDecode=deStr
    end function
     
    function isvalidhex(str)
      isvalidhex=true
      str=ucase(str)
      if len(str)<>3 then isvalidhex=false:exit function
      if left(str,1)<>"%" then isvalidhex=false:exit function
      c=mid(str,2,1)
      if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
      c=mid(str,3,1)
      if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
    end function

    判断包含双字节字符的字符串长度函数

    这个好用,比LEN好多了
     
    '判断包含双字节字符的字符串长度
    Function getStrLen(str)
    dim x,y,i
    x = len(str)
    y = 0
    for i = 1 to x
    if asc(mid(str,i,1))<0 or asc(mid(str,i,1))>255 then
    y = y + 2 '双字节
    else
    y = y + 1'ascii码字符
    end if
    next
    getStrLen = y
    End Function
    '从指定(包含双字节字符的)字符串中第一个字符起的指定长度的字符串
    '指定的长度为单字节长度,即字节数
    Function leftString(str,length)
    dim x,y,i,s
    s=str
    x = len(str)
    y = 0
    if x >= 1 then
    for i = 1 to x
    if asc(mid(str,i,1)) < 0 or asc(mid(str,i,1)) >255 then
    y = y + 2
    else
    y = y + 1
    end if
    if y >= length then
    s = left(str,i) '字符串字节数
    exit for
    end if
    next
    end if
    leftString = s
    End Function

    汉字转拼音首字母函数

    先声明这个只对GB2312编码有用,因为他是根据ASCII编码来判断的,害我在UTF-8下面试了很久都不行!!UTF-8的暂时没有,勉强找到个是根据自定义表来判断的,很多都查不到,感觉没什么用,CSDN上问了都没人会……
     
    function getpychar(char)
    tmp=65536+asc(char)
    if(tmp>=45217 and tmp<=45252) then
    getpychar= "a"
    elseif(tmp>=45253 and tmp<=45760) then
    getpychar= "b"
    elseif(tmp>=45761 and tmp<=46317) then
    getpychar= "c"
    elseif(tmp>=46318 and tmp<=46825) then
    getpychar= "d"
    elseif(tmp>=46826 and tmp<=47009) then
    getpychar= "e"
    elseif(tmp>=47010 and tmp<=47296) then
    getpychar= "f"
    elseif(tmp>=47297 and tmp<=47613) then
    getpychar= "g"
    elseif(tmp>=47614 and tmp<=48118) then
    getpychar= "h"
    elseif(tmp>=48119 and tmp<=49061) then
    getpychar= "j"
    elseif(tmp>=49062 and tmp<=49323) then
    getpychar= "k"
    elseif(tmp>=49324 and tmp<=49895) then
    getpychar= "l"
    elseif(tmp>=49896 and tmp<=50370) then
    getpychar= "m"
    elseif(tmp>=50371 and tmp<=50613) then
    getpychar= "n"
    elseif(tmp>=50614 and tmp<=50621) then
    getpychar= "o"
    elseif(tmp>=50622 and tmp<=50905) then
    getpychar= "p"
    elseif(tmp>=50906 and tmp<=51386) then
    getpychar= "q"
    elseif(tmp>=51387 and tmp<=51445) then
    getpychar= "r"
    elseif(tmp>=51446 and tmp<=52217) then
    getpychar= "s"
    elseif(tmp>=52218 and tmp<=52697) then
    getpychar= "t"
    elseif(tmp>=52698 and tmp<=52979) then
    getpychar= "w"
    elseif(tmp>=52980 and tmp<=53640) then
    getpychar= "x"
    elseif(tmp>=53689 and tmp<=54480) then
    getpychar= "y"
    elseif(tmp>=54481 and tmp<=62289) then
    getpychar= "z"
    else
    getpychar=char
    end if
    end function
     
    function getpy(str)
    for i=1 to len(str)
    getpy=getpy&getpychar(mid(str,i,1))
    next
    msgbox getpy
    end function