• <em id="52tge"><object id="52tge"><blockquote id="52tge"></blockquote></object></em>

  • <progress id="52tge"></progress>
      
      
      <tbody id="52tge"><pre id="52tge"></pre></tbody>
      <em id="52tge"></em>
      <li id="52tge"><acronym id="52tge"><u id="52tge"></u></acronym></li>

      <nav id="52tge"><sub id="52tge"><noframes id="52tge"></noframes></sub></nav>

      網站地圖 | RSS訂閱 老鐵博客 - 上海SEO優化|上海網站建設|蜘蛛池出租|站群代搭建
      你的位置:首頁 ? ASP程序 ? 正文

      ASP生成數字字母圖片驗證碼,可設置位數

      2015-12-31 10:0:13 | 作者:老鐵SEO | 3個評論 | 人瀏覽

      點擊此處在線預覽效果

      HTML中調用代碼如下:

      <img src="getcheckcode.asp?checkcodename=checkcode" alt="驗證碼" border="0" width="60" height="20" title="看不清?點一下" align="bottom" onclick="javascript:this.src='getcheckcode.asp?checkcodename=checkcode&getrandom=' + Math.random() ;" style="cursor:pointer;" />

       

      ASP文件名稱為:getcheckcode.asp,代碼如下(僅此一個ASP文件即可生成,無需其它文件):

      <%

      '制作:凌陳亮www.wgsygc.com(QQ:57404811)
      '此為修改網上下的代碼,現可設置驗證碼位數,字符點陣二進制碼(獨創12*12點陣)和部分程序已改,另增加注釋說明

      Call Com_CreatValidCode(trim(request.QueryString("checkcodename")))

      Sub Com_CreatValidCode(pSN) '參數:驗證碼SESSION名稱

          Response.Expires = -9999
          Response.AddHeader "Pragma","no-cache"
          Response.AddHeader "cache-ctrol","no-cache"
          Response.ContentType = "Image/BMP"

          Randomize

          Dim i, ii, iii
       
       const cnum=4 '驗證碼位數,從0開始,3表示4位
       
          Const cOdds = 0 ' 雜點出現的機率
          'Const cAmount = 10 ' 文字數量:前面多少個字符中隨機篩選,10為純數字
          Const cAmount = 36 ' 文字數量,36為數字字母混合
          Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         const cwidth=12 '字寬(要為4的倍數),固定值,不可修改
         const cheight=12 '字高,固定值,不可修改

          ' 隨機產生字符
          redim vCode(cnum)
       dim vCodes
          For i = 0 To cnum
              vCode(i) = Int(Rnd * cAmount)
              vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
          Next

          Session(pSN) = vCodes '記錄入Session

          ' 字符的數據
          Dim vNumberData(35)
          vNumberData(0) = "111111111111111000000111110111111011110111111011110110011011110110011011110110011011110110011011110111111011110111111011111000000111111111111111"
          vNumberData(1) = "111111111111111110111111111000111111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111000001111111111111111"
          vNumberData(2) = "111111111111111100001111111011110111111011110111111111110111111111101111111111011111111110111111111101111111111011110111111000000111111111111111"
          vNumberData(3) = "111111111111111100001111111011110111111011110111111111101111111110011111111111101111111111110111111011110111111011110111111100001111111111111111"
          vNumberData(4) = "111111111111111111011111111111011111111110011111111101011111111011011111111011011111111000000111111111011111111111011111111110000111111111111111"
          vNumberData(5) = "111111111111111000000111111011111111111011111111111010001111111001110111111111110111111111110111111011110111111011110111111100001111111111111111"
          vNumberData(6) = "111111111111111110001111111101110111111011111111111011111111111010001111111001110111111011110111111011110111111011110111111100001111111111111111"
          vNumberData(7) = "111111111111111000000111111011101111111011101111111111011111111111011111111110111111111110111111111110111111111110111111111110111111111111111111"
          vNumberData(8) = "111111111111111100001111111011110111111011110111111011110111111100001111111101101111111011110111111011110111111011110111111100001111111111111111"
          vNumberData(9) = "111111111111111100011111111011101111111011110111111011110111111011100111111100010111111111110111111111110111111011101111111100011111111111111111"
          vNumberData(10) = "111111111111111110111111111110111111111101011111111101011111111101011111111101011111111000001111111011101111111011101111110001000111111111111111"
          vNumberData(11) = "111111111111110000001111111011110111111011110111111011101111111000011111111011101111111011110111111011110111111011110111110000001111111111111111"
          vNumberData(12) = "111111111111111100000111111011110111110111110111110111111111110111111111110111111111110111111111110111110111111011101111111100011111111111111111"
          vNumberData(13) = "111111111111110000011111111011101111111011110111111011110111111011110111111011110111111011110111111011110111111011101111110000011111111111111111"
          vNumberData(14) = "111111111111110000001111111011110111111011011111111011011111111000011111111011011111111011011111111011111111111011110111110000001111111111111111"
          vNumberData(15) = "111111111111110000001111111011110111111011011111111011011111111000011111111011011111111011011111111011111111111011111111110001111111111111111111"
          vNumberData(16) = "111111111111111100001111111011101111110111101111110111111111110111111111110111111111110111000111110111101111111011101111111100011111111111111111"
          vNumberData(17) = "111111111111110001000111111011101111111011101111111011101111111000001111111011101111111011101111111011101111111011101111110001000111111111111111"
          vNumberData(18) = "111111111111111000001111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111000001111111111111111"
          vNumberData(19) = "111111111111111100000111111111011111111111011111111111011111111111011111111111011111111111011111111111011111110111011111110000111111111111111111"
          vNumberData(20) = "111111111111110001000111111011101111111011011111111010111111111000111111111010111111111011011111111011011111111011101111110001000111111111111111"
          vNumberData(21) = "111111111111110001111111111011111111111011111111111011111111111011111111111011111111111011111111111011111111111011110111110000000111111111111111"
          vNumberData(22) = "111111111111110001000111111001001111111001001111111001001111111010101111111010101111111010101111111010101111111010101111110010100111111111111111"
          vNumberData(23) = "111111111111110001000111111001101111111001101111111010101111111010101111111010101111111011001111111011001111111011001111110001101111111111111111"
          vNumberData(24) = "111111111111111100011111111011101111110111110111110111110111110111110111110111110111110111110111110111110111111011101111111100011111111111111111"
          vNumberData(25) = "111111111111110000001111111011110111111011110111111011110111111000001111111011111111111011111111111011111111111011111111110001111111111111111111"
          vNumberData(26) = "111111111111111100011111111011101111110111110111110111110111110111110111110111110111110111110111110100110111111011001111111100010111111111111111"
          vNumberData(27) = "111111111111110000011111111011101111111011101111111011101111111000011111111010111111111011011111111011011111111011101111110001100111111111111111"
          vNumberData(28) = "111111111111111100000111111011110111111011110111111011111111111100111111111111001111111111110111111011110111111011110111111000001111111111111111"
          vNumberData(29) = "111111111111110000000111110110110111111110111111111110111111111110111111111110111111111110111111111110111111111110111111111100011111111111111111"
          vNumberData(30) = "111111111111110001000111111011101111111011101111111011101111111011101111111011101111111011101111111011101111111011101111111100011111111111111111"
          vNumberData(31) = "111111111111110001000111111011101111111011101111111011101111111101011111111101011111111101011111111101011111111110111111111110111111111111111111"
          vNumberData(32) = "111111111111110010100111111010101111111010101111111010101111111010101111111001001111111101011111111101011111111101011111111101011111111111111111"
          vNumberData(33) = "111111111111110001000111111011101111111101011111111101011111111110111111111110111111111101011111111101011111111011101111110001000111111111111111"
          vNumberData(34) = "111111111111110001000111111011101111111011101111111101011111111101011111111110111111111110111111111110111111111110111111111100011111111111111111"
          vNumberData(35) = "111111111111111000000111111011101111111111101111111111011111111111011111111110111111111110111111111101111111111101110111111000000111111111111111"
       dim picwidth : picwidth=(cnum+1)*cwidth '字符個數*字寬=圖片寬度
       dim picdatasize : picdatasize=picwidth*cheight*3 '寬*高*3
       dim filesize : filesize=picdatasize+54
          ' 輸出圖像文件頭
          Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(filesize mod 256) & chrB((filesize\256) mod 256) & ChrB(((filesize\256)\256) mod 256) & ChrB(((filesize\256)\256)\256) &_
        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(picwidth mod 256) & chrB((picwidth\256) mod 256) & ChrB(((picwidth\256)\256) mod 256) & ChrB(((picwidth\256)\256)\256) & ChrB(cheight mod 256) & chrB((cheight\256) mod 256) & ChrB(((cheight\256)\256) mod 256) & ChrB(((cheight\256)\256)\256) & ChrB(1) & ChrB(0)
      '文件標識(2bytes):ChrB(66) & ChrB(77) 即BM
      '文件大小(1dword):ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0)
      '保留字(1dword):ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)           說明:保留,必須設置為0
      '偏移量(1dword):ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0)          說明:從文件開始到位圖數據開始之間的數據偏移量
      '位圖信息頭長度(1dword):ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) 
      '位圖的寬度(1word):ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0)       說明:單位為像素
      '位圖的高度(1dword):ChrB(10) & ChrB(0) & ChrB(0) & ChrB(0)
      '位圖的位面數(1dword):ChrB(1) & ChrB(0)                         說明:該值總為1

          ' 輸出圖像信息頭
          Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
        ChrB(picdatasize Mod 256) & ChrB((picdatasize\256) Mod 256) & ChrB((picdatasize\256\256) Mod 256) & ChrB(picdatasize\256\256\256) & 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)
      '每個像素的位數(2bytes):ChrB(24) & ChrB(0) 說明:1-單色位圖;4-16色位圖;8-256色位圖;16-16bit;24-24bits;32-32bit
      '壓縮說明(1dword):ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 說明:0-不壓縮;1-rel8壓縮;2-rel4壓縮;3-bitfields一位域存放
      '用字節數表示位圖數據大小(1dword):ChrB(176) & ChrB(4) & ChrB(0) & ChrB(0) 說明:4的倍數;
      '水平分辨率(1dword):ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0)  說明:單位為,像素/米
      '垂直分辨率(1dword):ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0)
      '位圖使用的顏色數(1dword):ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
      '重要顏色數(1dword):ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)    說明:0-表示所有數據一樣重要

       redim temp_color(cnum),tem_i(cnum)
          For i = cheight-1 To 0 Step -1 ' 歷經所有行(按高的每1px逐行輸出)
              For ii = 0 To cnum ' 歷經所有字符
                  For iii = 1 To cwidth ' 歷經所有像素(按字符寬度逐像素輸出)
                  ' 逐行、逐字、逐像素地輸出圖像數據
                      If Rnd * 99 + 1 < cOdds Then '隨機生成雜點
           Response.BinaryWrite com_vColorData(1) '輸出雜點
                      Else
           dim abc : abc=clng(Mid(vNumberData(vCode(ii)), i * cwidth + iii, 1))
           if abc=1 then
            Response.BinaryWrite com_vColorData(0) '輸出背景
           else
            if tem_i(ii)<>1 then
             tem_i(ii)=1
             temp_color(ii)=com_vColorData(1) '獲取字符顏色
            end if
            Response.BinaryWrite temp_color(ii) '輸出字符
           end if
                      End If
                  Next
              Next
          Next
      End Sub

      ' 顏色的數據(背景/字符)
      function com_vColorData(n)
       dim return
       if n=0 then '背景
        return=ChrB(250) & ChrB(240) & ChrB(230) '淡藍色
       else '字符
        return=ChrB(clng(rnd*220)) & ChrB(clng(rnd*210)) & ChrB(clng(rnd*200)) '前景
       end if
       com_vColorData=return
      end function

      %>

       

    1. 本文來自: 老鐵博客,轉載請保留出處!歡迎發表您的評論
    2. 相關標簽:獲取字符串  驗證碼  隨機數  
    3. 已有3位網友發表了一針見血的評論,你還等什么?

      必填

      選填

      記住我,下次回復時不用重新輸入個人信息

      必填,不填不讓過哦,嘻嘻。

      ◎歡迎參與討論,請在這里發表您的看法、交流您的觀點。

      色情激情片日本大全|亚洲无码色情gif|六人行成人版第九影院|亚洲成人电影理论电影

    4. <em id="52tge"><object id="52tge"><blockquote id="52tge"></blockquote></object></em>

    5. <progress id="52tge"></progress>
        
        
        <tbody id="52tge"><pre id="52tge"></pre></tbody>
        <em id="52tge"></em>
        <li id="52tge"><acronym id="52tge"><u id="52tge"></u></acronym></li>

        <nav id="52tge"><sub id="52tge"><noframes id="52tge"></noframes></sub></nav>