Asp图片验证码
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[p]保存下面代码到code.asp,在需要显示验证码的地方使用 [br]来显示,使用session("getcode") 来提取验证码 [/p]
[p]如果需要使用点击一下更换图片的效果,可以使用:[br][/p] [url=javascript:void(0);][/url] <% [br]option explicit [br]response.buffer=true [br]call com_creatvalidcode("getcode") [br]sub com_creatvalidcode(psn) [br]response.expires = -1 [br]response.addheader "pragma","no-cache" [br]response.addheader "cache-ctrol","no-cache" [br]response.contenttype = "image/bmp" [br]randomize [br]dim i, ii, iii [br]const codds = 6 ' 杂点出现的机率 [br]const camount = 10 ' 文字数量 [br]const ccode = "0123456789abcd" [br]' 颜色的数据(字符,背景) [br]dim vcolordata(1) [br]vcolordata(0) = chrb(0) & chrb(0) & chrb(255) ' 蓝0,绿0,红0(黑色) [br]vcolordata(1) = chrb(255) & chrb(255) & chrb(255) ' 蓝250,绿236,红211(浅蓝色) [br]' 随机产生字符 [br]dim vcode(4), vcodes [br]for i = 0 to 3 [br]vcode(i) = int(rnd * camount) [br]vcodes = vcodes & mid(ccode, vcode(i) + 1, 1) [br]next [br]session(psn) = vcodes '记录入session [br]' 字符的数据 [br]dim vnumberdata(9) [br]vnumberdata(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111" [br]vnumberdata(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111" [br]vnumberdata(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011" [br]vnumberdata(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111" [br]vnumberdata(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011" [br]vnumberdata(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111" [br]vnumberdata(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111" [br]vnumberdata(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111" [br]vnumberdata(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111" [br]vnumberdata(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111" [br]' 输出图像文件头 [br]response.binarywrite chrb(66) & chrb(77) & chrb(230) & chrb(4) & chrb(0) & chrb(0) & chrb(0) & chrb(0) &_ [br]chrb(0) & chrb(0) & chrb(54) & chrb(0) & chrb(0) & chrb(0) & chrb(40) & chrb(0) &_ [br]chrb(0) & chrb(0) & chrb(40) & chrb(0) & chrb(0) & chrb(0) & chrb(10) & chrb(0) &_ [br]chrb(0) & chrb(0) & chrb(1) & chrb(0) [br]' 输出图像信息头 [br]response.binarywrite chrb(24) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(176) & chrb(4) &_ [br]chrb(0) & chrb(0) & chrb(18) & chrb(11) & chrb(0) & chrb(0) & chrb(18) & chrb(11) &_ [br]chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) &_ [br]chrb(0) & chrb(0) [br]for i = 9 to 0 step -1 ' 历经所有行 [br]for ii = 0 to 3 ' 历经所有字 [br]for iii = 1 to 10 ' 历经所有像素 [br]' 逐行、逐字、逐像素地输出图像数据 [br]if rnd * 99 + 1 < codds then ' 随机生成杂点 [br]response.binarywrite vcolordata(0) [br]else [br]response.binarywrite vcolordata(mid(vnumberdata(vcode(ii)), i * 10 + iii, 1)) [br]end if [br]next [br]next [br]next [br]end sub [br]%> 该文章在 2010/7/8 13:45:13 编辑过 |
关键字查询
相关文章
正在查询... |