This article will share with you a verification code function implemented using Asp, and it is refreshed. The code is very concise and practical. Friends in need can refer to it.
Put the following code on a separate page checkcode.asp
- <%
- OptionExplicit
- Response.buffer=true
- CallCom_CreatValidCode(validateCode)
- SubCom_CreatValidCode(pSN)
- 'No caching
- Response.Expires=-9999
- Response.AddHeaderPragma,no-cache
- Response.AddHeadercache-ctrol,no-cache
- Response.ContentType=Image/BMP
- Randomize
- Dimi,ii,iii
- ConstcOdds=2'The probability of miscellaneous spots appearing
- ConstcAmount=10'Number of text
- ConstcCode=0123456789
- 'Color data (characters, background)
- DimvColorData(1)
- vColorData(0)=ChrB(0)&ChrB(0)&ChrB(211)'Blue 0, green 0, red 0 (black)
- vColorData(1)=ChrB(255)&ChrB(255)&ChrB(255)'Blue 250, green 236, red 211 (light blue)
- 'Randomly generated characters
- DimvCode(4),vCodes
- Fori=0To3
- vCode(i)=Int(Rnd*cAmount)
- vCodes=vCodes&Mid(cCode,vCode(i)+1,1)
- Next
- Session(pSN)=vCodes' record into Session
- 'character data
- DimvNumberData(9)
- vNumberData(0)=
- 1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111
- 110000111
- vNumberData(1)=
- 1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111
- 100000111
- vNumberData(2)=
- 1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111
- 100000011
- vNumberData(3)=
- 1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111
- 110000111
- vNumberData(4)=
- 1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111
- 111000011
- vNumberData(5)=
- 1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111
- 110000111
- vNumberData(6)=
- 1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111
- 110000111
- vNumberData(7)=
- 1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111
- 111011111
- vNumberData(8)=
- 1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111
- 110000111
- vNumberData(9)=
- 1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111
- 110001111
- 'Output image file header
- Response.BinaryWriteChrB(66)&ChrB(77)&ChrB(230)&ChrB(4)&ChrB(0)&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(0)&ChrB(1)&ChrB(0)
- 'Output image information header
- Response.BinaryWriteChrB(24)&ChrB(0)&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)&_
- ChrB(0)&ChrB(0)
- Fori=9To0Step-1' has gone through all the lines
- Forii=0To3' has passed all words
- Foriii=1To10' has passed all pixels
- 'Output image data line by line, word by word, pixel by pixel
- IfRnd*99+1<cOddsThen' Randomly generates miscellaneous points
- Response.BinaryWritevColorData(0)
- Else
- Response.BinaryWritevColorData(Mid(vNumberData(vCode(ii)),i*10+iii,1))
- EndIf
- Next
- Next
- Next
- EndSub
- %>
The pages you need to use are quoted in the following way:
Verification code: src=checkcode.asp cellpadding="0" cellpacing="0" style="border-collapse: collapse; border-spacing: 0px; width: 780px; clear: both; padding: 0px !important; margin: 0px !important; font-size: 1em !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; min-height: inherit !important; ">
The above is the entire content of this article, I hope you like it.