1. <small id="zslv9"><ul id="zslv9"></ul></small>
      1. <u id="zslv9"></u>

          \n    \n    

          name:<\/p>\n    

          Captcha:Please click full circle
          \" style=\"cursor:pointer\"><\/p>\n    

          <\/p>\n    \n    \n    <\/form>\n <\/body>\n<\/html>\n<\/pre>

          本篇文章講解了關于php click captcha 驗證碼類的介紹,更多相關內容請關注php中文網(wǎng)。<\/span><\/p>\n

          相關推薦:<\/p>\n

          ?關于HTML5 history API 的介紹<\/a><\/p>\n

          關于冒泡,二分法插入,快速排序算法的介紹<\/a>
          <\/p>\n

          講解php 支持斷點續(xù)傳的文件下載類的相關內容<\/a>
          <\/p>"}

          国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

          首頁 后端開發(fā) php教程 關于php click captcha 驗證碼類的介紹

          關于php click captcha 驗證碼類的介紹

          Jun 11, 2018 am 10:21 AM
          captcha php

          需求:

          現(xiàn)在常用的表單驗證碼大部分都是要用戶輸入為主,但這樣對手機用戶會不方便。

          如果手機用戶訪問,可以不用輸入,而是click某一位置便可確認驗證碼,這樣就會方便很多。

          原理:

          1.使用PHP?imagecreate創(chuàng)建PNG圖象,在圖中畫N個圓弧,其中一個是完整的圓(驗證用),將圓心坐標及半徑記錄入session。

          2.在瀏覽器,當用戶在驗證碼圖片上點擊時,記錄點擊的位置。

          3.將用戶點擊的坐標與session記錄的圓心坐標、半徑比較,判斷是否在圓中,如是則驗證通過。


          ClickCaptcha.class.php

          <?php
          /** Click Captcha 驗證碼類
          *   Date:   2013-05-04
          *   Author: fdipzone
          *   Ver:    1.0
          */
          
          class ClickCaptcha { // class start
          
              public $sess_name = &#39;m_captcha&#39;;
              public $width = 500;
              public $height = 200;
              public $icon = 5;
              public $iconColor = array(255, 255, 0);
              public $backgroundColor = array(0, 0, 0);
              public $iconSize = 56;
          
              private $_img_res = null;
          
          
              public function __construct($sess_name=&#39;&#39;){
                  if(session_id() == &#39;&#39;){
                      session_start();
                  }
          
                  if($sess_name!=&#39;&#39;){
                      $this->sess_name = $sess_name; // 設置session name
                  }
              }
          
          
              /** 創(chuàng)建驗證碼 */
              public function create(){
          
                  // 創(chuàng)建圖象
                  $this->_img_res = imagecreate($this->width, $this->height);
                  
                  // 填充背景
                  ImageColorAllocate($this->_img_res, $this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
          
                  // 分配顏色
                  $col_ellipse = imagecolorallocate($this->_img_res, $this->iconColor[0], $this->iconColor[1], $this->iconColor[2]);
          
                  $minArea = $this->iconSize/2+3;
          
                  // 混淆用圖象,不完整的圓
                  for($i=0; $i<$this->icon; $i++){
                      $x = mt_rand($minArea, $this->width-$minArea);
                      $y = mt_rand($minArea, $this->height-$minArea);
                      $s = mt_rand(0, 360);
                      $e = $s + 330;
                      imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, $s, $e, $col_ellipse);            
                  }
          
                  // 驗證用圖象,完整的圓
                  $x = mt_rand($minArea, $this->width-$minArea);
                  $y = mt_rand($minArea, $this->height-$minArea);
                  $r = $this->iconSize/2;
                  imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, 0, 360, $col_ellipse);        
          
                  // 記錄圓心坐標及半徑
                  $this->captcha_session($this->sess_name, array($x, $y, $r));
          
                  // 生成圖象
                  Header("Content-type: image/PNG");
                  ImagePNG($this->_img_res);
                  ImageDestroy($this->_img_res);
          
                  exit();
              }
          
          
              /** 檢查驗證碼
              * @param String $captcha  驗證碼
              * @param int    $flag     驗證成功后 0:不清除session 1:清除session
              * @return boolean
              */
              public function check($captcha, $flag=1){
                  if(trim($captcha)==&#39;&#39;){
                      return false;
                  }
                  
                  if(!is_array($this->captcha_session($this->sess_name))){
                      return false;
                  }
          
                  list($px, $py) = explode(&#39;,&#39;, $captcha);
                  list($cx, $cy, $cr) = $this->captcha_session($this->sess_name);
          
                  if(isset($px) && is_numeric($px) && isset($py) && is_numeric($py) && 
                      isset($cx) && is_numeric($cx) && isset($cy) && is_numeric($cy) && isset($cr) && is_numeric($cr)){
                      if($this->pointInArea($px,$py,$cx,$cy,$cr)){
                          if($flag==1){
                              $this->captcha_session($this->sess_name,&#39;&#39;);
                          }
                          return true;
                      }
                  }
                  return false;
              }
          
          
              /** 判斷點是否在圓中
              * @param int $px  點x
              * @param int $py  點y
              * @param int $cx  圓心x
              * @param int $cy  圓心y
              * @param int $cr  圓半徑
              * sqrt(x^2+y^2)<r
              */
              private function pointInArea($px, $py, $cx, $cy, $cr){
                  $x = $cx-$px;
                  $y = $cy-$py;
                  return round(sqrt($x*$x + $y*$y))<$cr;
              }
          
          
              /** 驗證碼session處理方法
              * @param   String   $name    captcha session name
              * @param   String   $value
              * @return  String
              */
              private function captcha_session($name,$value=null){
                  if(isset($value)){
                      if($value!==&#39;&#39;){
                          $_SESSION[$name] = $value;
                      }else{
                          unset($_SESSION[$name]);
                      }
                  }else{
                      return isset($_SESSION[$name])? $_SESSION[$name] : &#39;&#39;;
                  }
              }
          
          } // class end
          
          ?>

          demo.php

          <?php
          session_start();
          require(&#39;ClickCaptcha.class.php&#39;);
          
          if(isset($_GET[&#39;get_captcha&#39;])){ // get captcha
              $obj = new ClickCaptcha();
              $obj->create();
              exit();
          }
          
          if(isset($_POST[&#39;send&#39;]) && $_POST[&#39;send&#39;]==&#39;true&#39;){ // submit
              $name = isset($_POST[&#39;name&#39;])? trim($_POST[&#39;name&#39;]) : &#39;&#39;;
              $captcha = isset($_POST[&#39;captcha&#39;])? trim($_POST[&#39;captcha&#39;]) : &#39;&#39;;
          
              $obj = new ClickCaptcha();
          
              if($obj->check($captcha)){
                  echo &#39;your name is:&#39;.$name;
              }else{
                  echo &#39;captcha not match&#39;;
              }
              echo &#39; <a href="demo.php">back</a>&#39;;
          
          }else{ // html
          ?>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
          <html>
           <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <title> Click Captcha Demo </title>
            <script type="text/javascript" src="jquery-1.6.2.min.js"></script>
            <script type="text/javascript">
              $(function(){
                  $(&#39;#captcha_img&#39;).click(function(e){
                      var x = e.pageX - $(this).offset().left;
                      var y = e.pageY - $(this).offset().top;
                      $(&#39;#captcha&#39;).val(x+&#39;,&#39;+y);
                  })
          
                  $(&#39;#btn&#39;).click(function(e){
                      if($.trim($(&#39;#name&#39;).val())==&#39;&#39;){
                          alert(&#39;Please input name!&#39;);
                          return false;
                      }
          
                      if($.trim($(&#39;#captcha&#39;).val())==&#39;&#39;){
                          alert(&#39;Please click captcha!&#39;);
                          return false;
                      }
                      $(&#39;#form1&#39;)[0].submit();
                  })
              })
            </script>
           </head>
          
           <body>
              <form name="form1" id="form1" method="post" action="demo.php" onsubmit="return false">
              <p>name:<input type="text" name="name" id="name"></p>
              <p>Captcha:Please click full circle<br><img id="captcha_img" src="demo.php?get_captcha=1&t=<?=time() ?>" style="cursor:pointer"></p>
              <p><input type="submit" id="btn" value="submit"></p>
              <input type="hidden" name="send" value="true">
              <input type="hidden" name="captcha" id="captcha">
              </form>
           </body>
          </html>
          <?php } ?>

          本篇文章講解了關于php click captcha 驗證碼類的介紹,更多相關內容請關注php中文網(wǎng)。

          相關推薦:

          ?關于HTML5 history API 的介紹

          關于冒泡,二分法插入,快速排序算法的介紹

          講解php 支持斷點續(xù)傳的文件下載類的相關內容

          以上是關于php click captcha 驗證碼類的介紹的詳細內容。更多信息請關注PHP中文網(wǎng)其他相關文章!

          本站聲明
          本文內容由網(wǎng)友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內容,請聯(lián)系admin@php.cn

          熱AI工具

          Undress AI Tool

          Undress AI Tool

          免費脫衣服圖片

          Undresser.AI Undress

          Undresser.AI Undress

          人工智能驅動的應用程序,用于創(chuàng)建逼真的裸體照片

          AI Clothes Remover

          AI Clothes Remover

          用于從照片中去除衣服的在線人工智能工具。

          Clothoff.io

          Clothoff.io

          AI脫衣機

          Video Face Swap

          Video Face Swap

          使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

          熱工具

          記事本++7.3.1

          記事本++7.3.1

          好用且免費的代碼編輯器

          SublimeText3漢化版

          SublimeText3漢化版

          中文版,非常好用

          禪工作室 13.0.1

          禪工作室 13.0.1

          功能強大的PHP集成開發(fā)環(huán)境

          Dreamweaver CS6

          Dreamweaver CS6

          視覺化網(wǎng)頁開發(fā)工具

          SublimeText3 Mac版

          SublimeText3 Mac版

          神級代碼編輯軟件(SublimeText3)

          在C中使用std :: Chrono 在C中使用std :: Chrono Jul 15, 2025 am 01:30 AM

          std::chrono在C 中用于處理時間,包括獲取當前時間、測量執(zhí)行時間、操作時間點與持續(xù)時間及格式化解析時間。1.獲取當前時間使用std::chrono::system_clock::now(),可轉換為可讀字符串但系統(tǒng)時鐘可能不單調;2.測量執(zhí)行時間應使用std::chrono::steady_clock以確保單調性,并通過duration_cast轉換為毫秒、秒等單位;3.時間點(time_point)和持續(xù)時間(duration)可相互操作,但需注意單位兼容性和時鐘紀元(epoch)

          PHP如何處理環(huán)境變量? PHP如何處理環(huán)境變量? Jul 14, 2025 am 03:01 AM

          toAccessenvironmentVariablesInphp,useGetenv()或$ _envsuperglobal.1.getEnv('var_name')retievesSpecificvariable.2。$ _ en v ['var_name'] accessesvariablesifvariables_orderInphp.iniincludes“ e” .setVariablesViaCliWithvar = vualitephpscript.php,inapach

          為什么我們評論:PHP指南 為什么我們評論:PHP指南 Jul 15, 2025 am 02:48 AM

          PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

          PHP檢查字符串是否以特定的字符串開頭 PHP檢查字符串是否以特定的字符串開頭 Jul 14, 2025 am 02:44 AM

          在PHP中判斷字符串是否以特定字符串開頭可通過多種方法實現(xiàn):1.使用strncmp()比較前n個字符,若返回0則開頭匹配,不區(qū)分大小寫;2.使用strpos()檢查子字符串位置是否為0,區(qū)分大小寫,可用stripos()替代實現(xiàn)不區(qū)分大小寫;3.可封裝startsWith()或str_starts_with()函數(shù)提高復用性;此外需注意空字符串默認返回true、編碼兼容性及性能差異,strncmp()通常效率更高。

          如何避免PHP中未定義的索引錯誤 如何避免PHP中未定義的索引錯誤 Jul 14, 2025 am 02:51 AM

          避免“undefinedindex”錯誤的關鍵方法有三:首先,使用isset()檢查數(shù)組鍵是否存在并確保值不為null,適用于大多數(shù)常規(guī)場景;其次,使用array_key_exists()僅判斷鍵是否存在,適用于需要區(qū)分鍵不存在和值為null的情況;最后,使用空合并運算符??(PHP7 )簡潔地設置默認值,推薦用于現(xiàn)代PHP項目,同時注意表單字段名拼寫、謹慎使用extract()及遍歷前檢查數(shù)組非空以進一步規(guī)避風險。

          php準備的語句與條款 php準備的語句與條款 Jul 14, 2025 am 02:56 AM

          使用PHP預處理語句執(zhí)行帶有IN子句的查詢時,1.需根據(jù)數(shù)組長度動態(tài)生成占位符;2.使用PDO時可直接傳入數(shù)組,用array_values確保索引連續(xù);3.使用mysqli時需構造類型字符串并綁定參數(shù),注意展開數(shù)組的方式及版本兼容性;4.避免拼接SQL、處理空數(shù)組和確保數(shù)據(jù)類型匹配。具體做法是:先用implode與array_fill生成占位符,再依擴展特性綁定參數(shù),從而安全執(zhí)行IN查詢。

          如何在Windows上安裝PHP 如何在Windows上安裝PHP Jul 15, 2025 am 02:46 AM

          安裝PHP在Windows上的關鍵步驟包括:1.下載合適的PHP版本并解壓,推薦使用ThreadSafe版本配合Apache或NonThreadSafe版本配合Nginx;2.配置php.ini文件,將php.ini-development或php.ini-production重命名為php.ini;3.將PHP路徑添加到系統(tǒng)環(huán)境變量Path中以便命令行使用;4.測試PHP是否安裝成功,通過命令行執(zhí)行php-v和運行內置服務器測試解析能力;5.若使用Apache,需在httpd.conf中配置P

          PHP語法:基礎知識 PHP語法:基礎知識 Jul 15, 2025 am 02:46 AM

          PHP的基礎語法包括四個關鍵點:1.PHP標簽必須使用結束,推薦使用完整標簽;2.輸出內容常用echo和print,其中echo支持多參數(shù)且效率更高;3.注釋方式有//、#和//,用于提升代碼可讀性;4.每條語句必須以分號結尾,空格和換行不影響執(zhí)行但影響可讀性。掌握這些基本規(guī)則有助于寫出清晰穩(wěn)定的PHP代碼。

          See all articles