Asp圖片驗證碼
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
保存下面代碼到code.asp,在需要顯示驗證碼的地方使用 如果需要使用點擊一下更換圖片的效果,可以使用: <% option explicit response.buffer=true call com_creatvalidcode("getcode") sub com_creatvalidcode(psn) response.expires = -1 response.addheader "pragma","no-cache" response.addheader "cache-ctrol","no-cache" response.contenttype = "image/bmp" randomize dim i, ii, iii const codds = 6 ' 雜點出現(xiàn)的機率 const camount = 10 ' 文字數(shù)量 const ccode = "0123456789abcd" ' 顏色的數(shù)據(jù)(字符,背景) dim vcolordata(1) vcolordata(0) = chrb(0) & chrb(0) & chrb(255) ' 藍0,綠0,紅0(黑色) vcolordata(1) = chrb(255) & chrb(255) & chrb(255) ' 藍250,綠236,紅211(淺藍色) ' 隨機產(chǎn)生字符 dim vcode(4), vcodes for i = 0 to 3 vcode(i) = int(rnd * camount) vcodes = vcodes & mid(ccode, vcode(i) + 1, 1) next session(psn) = vcodes '記錄入session ' 字符的數(shù)據(jù) dim vnumberdata(9) 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" ' 輸出圖像文件頭 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 ' 歷經(jīng)所有行 for ii = 0 to 3 ' 歷經(jīng)所有字 for iii = 1 to 10 ' 歷經(jīng)所有像素 ' 逐行、逐字、逐像素地輸出圖像數(shù)據(jù) 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 %> 該文章在 2010/7/8 13:45:13 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |