Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12989843
  • 博文数量: 187
  • 博客积分: 7517
  • 博客等级: 少将
  • 技术积分: 1981
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-20 18:51
文章分类

全部博文(187)

文章存档

2015年(3)

2013年(4)

2012年(20)

2011年(2)

2010年(96)

2009年(14)

2008年(47)

2007年(1)

我的朋友

分类: 系统运维

2010-04-17 22:42:13

charAndNum_checkCode.asp

如下:

  1. <%   
  2. Sub ImageValidCode(sName)   
  3. Response.Expires = -1     
  4. Response.AddHeader "Pragma","no-cache"   
  5. Response.AddHeader "cache-ctrol","no-cache"   
  6. Response.ContentType = "Image/BMP"   
  7. Randomize   
  8. Dim i, ii, iii   
  9. Const cOdds = 4 '杂点出现的机率   
  10. Const cAmount = 36 ' 文字数量   
  11. Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" '颜色的数据(字符,背景)   
  12. Dim vColorData(1)   
  13. vColorData(0) = ChrB(255) & ChrB(000) & ChrB(000) '字符颜色   
  14. vColorData(1) = ChrB(000) & ChrB(255) & ChrB(255) '背景颜色   
  15. Dim vCode(4), vCodes   
  16. For i=0 To 3   
  17. vCode(i) = Int(Rnd * cAmount)   
  18. vCodes = vCodes & Mid(cCode, vCode(i)+1, 1)   
  19. Next   
  20. Session.Value(sName) = vCodes'记录入Session     
  21. Dim vNumberData(35)   
  22. vNumberData(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"   
  23. vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"   
  24. vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"   
  25. vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"   
  26. vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"   
  27. vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"   
  28. vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"   
  29. vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"   
  30. vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"   
  31. vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"   
  32. vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"   
  33. vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"   
  34. vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"   
  35. vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"   
  36. vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"   
  37. vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"   
  38. vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"   
  39. vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"   
  40. vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"   
  41. vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"   
  42. vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"   
  43. vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"   
  44. vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"   
  45. vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"   
  46. vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"   
  47. vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"   
  48. vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"   
  49. vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"   
  50. vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"   
  51. vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"   
  52. vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"   
  53. vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"   
  54. vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"   
  55. vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"   
  56. vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"   
  57. vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"   
  58.    ' 输出图像文件头   
  59. 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)   
  60.    ' 输出图像信息头   
  61. 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)   
  62. For i=9 To 0 Step -1 ' 历经所有行   
  63. For ii=0 To 3 ' 历经所有字   
  64. For iii=1 To 10 ' 历经所有像素   
  65. If Rnd * 99 + 1 < cOdds Then ' 随机生成杂点   
  66. Response.BinaryWrite vColorData(0)   
  67. Else   
  68. Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i*10+iii, 1))   
  69. End If   
  70. Next   
  71. Next   
  72. Next   
  73. End Sub   
  74.   
  75. Call ImageValidCode("GetCode")   
  76. %>   

web页面上的引用

Java代码 ASP英文字母加数字随机验证码(4位) - ^禹?铭^ - 禹铭思源 情意无限

  1.                          
  2.                            
  3.     
      
  4.            *验证码:   
  5.      
                          
  •       
  •     看不清楚?请点击刷新click="this.src=this.src+'?'+Math.random();" style="CURSOR:hand;">   
  •           
  •   
  • *验证码:
    看不清楚?请点击刷新click="this.src=this.src+'?'+Math.random();" style="CURSOR:hand;">

    注意输入的验证码与产生的验证码是否相同,应该在提交处理中验证,不能在页面上用JS获取Session验证,否则获得的session值将是上次产生的session值,主要原因是加载web页面与生成验证码图片不同步的问题

    提交页面的代码

    Java代码 ASP英文字母加数字随机验证码(4位) - ^禹?铭^ - 禹铭思源 情意无限

    1. checkCode = request.Form("checkCode")   
    2.   if (trim(checkCode)<>session("GetCode")) then   
    3.       Response.Write("")   
    4.       response.end   
    5.    end if  
    阅读(742) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~