欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作示例【附源碼下載】

 更新時間:2020年05月27日 09:38:12   作者:下頁、再停留  
這篇文章主要介紹了php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作,結(jié)合實例形式分析了php+js拖動滑塊驗證碼驗證表單操作基本功能實現(xiàn)與使用相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作。分享給大家供大家參考,具體如下:

現(xiàn)在很多網(wǎng)站,比如淘寶,京東等都改用使用極驗拖動驗證碼實現(xiàn)登錄,這種方式比傳統(tǒng)的驗證碼方式有更好的體驗,減少用戶輸入的錯誤,也同樣能起到防盜刷的功能?,F(xiàn)在很多極驗都是第三方的,也很多都是收費的。今天在這里給大家分享自己用原生php實現(xiàn)的一個極驗的代碼。用原生php的好處就是以后你要嵌套到什么框架,可以直接用核心代碼,改一改就好了。

極驗拖動動畫圖

代碼文件截圖

代碼實現(xiàn)

html文件

<!DOCTYPE html>
<html lang="">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>極驗滑塊拖動驗證碼-碼農(nóng)社區(qū)-web視頻分享網(wǎng)</title>
  <script type="text/javascript" src="tn_code.js?v=35"></script>
  <link rel="stylesheet" type="text/css" href="style.css?v=27" rel="external nofollow" />
<style type="text/css"></style>
</head>
<body style="text-align:center;">
<div class="tncode" style="text-align: center;margin: 100px auto;"></div>
<script type="text/javascript">
$TN.onsuccess(function(){
//驗證通過
});
</script> 

php文件:check.php

<?php
require_once dirname(__FILE__).'/TnCode.class.php';
$tn = new TnCode();
if($tn->check()){
    $_SESSION['tncode_check'] = 'ok';
  echo "ok";
}else{
    $_SESSION['tncode_check'] = 'error';
  echo "error";
}

?>

主要核心文件:TnCode.class.php

<?php
class TnCode
{
  var $im = null;
  var $im_fullbg = null;
  var $im_bg = null;
  var $im_slide = null;
  var $bg_width = 240;
  var $bg_height = 150;
  var $mark_width = 50;
  var $mark_height = 50;
  var $bg_num = 6;
  var $_x = 0;
  var $_y = 0;
  //容錯象素 越大體驗越好,越小破解難道越高
  var $_fault = 3;
  function __construct(){
    //ini_set('display_errors','On');
    //
    error_reporting(0);
    if(!isset($_SESSION)){
      session_start();
    }
  }
  function make(){
    $this->_init();
    $this->_createSlide();
    $this->_createBg();
    $this->_merge();
    $this->_imgout();
    $this->_destroy();
  }

  function check($offset=''){
    if(!$_SESSION['tncode_r']){
      return false;
    }
    if(!$offset){
      $offset = $_REQUEST['tn_r'];
    }
    $ret = abs($_SESSION['tncode_r']-$offset)<=$this->_fault;
    if($ret){
      unset($_SESSION['tncode_r']);
    }else{
      $_SESSION['tncode_err']++;
      if($_SESSION['tncode_err']>10){//錯誤10次必須刷新
        unset($_SESSION['tncode_r']);
      }
    }
    return $ret;
  }

  private function _init(){
    $bg = mt_rand(1,$this->bg_num);
    $file_bg = dirname(__FILE__).'/bg/'.$bg.'.png';
    $this->im_fullbg = imagecreatefrompng($file_bg);
    $this->im_bg = imagecreatetruecolor($this->bg_width, $this->bg_height);
    imagecopy($this->im_bg,$this->im_fullbg,0,0,0,0,$this->bg_width, $this->bg_height);
    $this->im_slide = imagecreatetruecolor($this->mark_width, $this->bg_height);
    $_SESSION['tncode_r'] = $this->_x = mt_rand(50,$this->bg_width-$this->mark_width-1);
    $_SESSION['tncode_err'] = 0;
    $this->_y = mt_rand(0,$this->bg_height-$this->mark_height-1);
  }

  private function _destroy(){
    imagedestroy($this->im);
    imagedestroy($this->im_fullbg);
    imagedestroy($this->im_bg);
    imagedestroy($this->im_slide);
  }
  private function _imgout(){
    if(!$_GET['nowebp']&&function_exists('imagewebp')){//優(yōu)先webp格式,超高壓縮率
      $type = 'webp';
      $quality = 40;//圖片質(zhì)量 0-100
    }else{
      $type = 'png';
      $quality = 7;//圖片質(zhì)量 0-9
    }
    header('Content-Type: image/'.$type);
    $func = "image".$type;
    $func($this->im,null,$quality);
  }
  private function _merge(){
    $this->im = imagecreatetruecolor($this->bg_width, $this->bg_height*3);
    imagecopy($this->im, $this->im_bg,0, 0 , 0, 0, $this->bg_width, $this->bg_height);
    imagecopy($this->im, $this->im_slide,0, $this->bg_height , 0, 0, $this->mark_width, $this->bg_height);
    imagecopy($this->im, $this->im_fullbg,0, $this->bg_height*2 , 0, 0, $this->bg_width, $this->bg_height);
    imagecolortransparent($this->im,0);//16777215
  }

  private function _createBg(){
    $file_mark = dirname(__FILE__).'/img/mark.png';
    $im = imagecreatefrompng($file_mark);
    header('Content-Type: image/png');
    //imagealphablending( $im, true);
    imagecolortransparent($im,0);//16777215
    //imagepng($im);exit;
    imagecopy($this->im_bg, $im, $this->_x, $this->_y , 0 , 0 , $this->mark_width, $this->mark_height);
    imagedestroy($im);
  }

  private function _createSlide(){
    $file_mark = dirname(__FILE__).'/img/mark2.png';
    $img_mark = imagecreatefrompng($file_mark);
    imagecopy($this->im_slide, $this->im_fullbg,0, $this->_y , $this->_x, $this->_y, $this->mark_width, $this->mark_height);
    imagecopy($this->im_slide, $img_mark,0, $this->_y , 0, 0, $this->mark_width, $this->mark_height);
    imagecolortransparent($this->im_slide,0);//16777215
    //header('Content-Type: image/png');
    //imagepng($this->im_slide);exit;
    imagedestroy($img_mark);
  }

}
?>

附:完整實例代碼點擊此處本站下載

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《PHP數(shù)學(xué)運算技巧總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

  • PHP解決短信驗證碼轟炸的方法詳解

    PHP解決短信驗證碼轟炸的方法詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用PHP解決短信驗證碼轟炸的問題,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以學(xué)習(xí)一下
    2023-12-12
  • PHP開發(fā)API接口簽名生成及驗證操作示例

    PHP開發(fā)API接口簽名生成及驗證操作示例

    這篇文章主要介紹了PHP開發(fā)API接口簽名生成及驗證操作,結(jié)合實例形式較為詳細(xì)的分析了PHP開發(fā)API接口簽名生成及驗證操作相關(guān)原理、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下
    2020-05-05
  • PHP $_SERVER詳解

    PHP $_SERVER詳解

    php編程中經(jīng)常需要用到一些服務(wù)器的一些資料,我把常用的用高亮的方式貼出來,其余的放在后面.方便以后查閱
    2009-01-01
  • 保證PHP對接API安全性的常見方法

    保證PHP對接API安全性的常見方法

    在對接API時,保證其安全性是非常重要的,本文給大家介紹了一些保證PHP對接API安全性的常見措施,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下
    2023-11-11
  • php 過濾英文標(biāo)點符號及過濾中文標(biāo)點符號代碼

    php 過濾英文標(biāo)點符號及過濾中文標(biāo)點符號代碼

    這篇文章主要介紹了php過濾英文標(biāo)點符號及過濾中文標(biāo)點符號的方法,需要的朋友可以參考下
    2014-06-06
  • php抓取頁面與代碼解析 推薦

    php抓取頁面與代碼解析 推薦

    在做一些天氣預(yù)報或者RSS訂閱的程序時,往往需要抓取非本地文件,一般情況下都是利用php模擬瀏覽器的訪問,通過http請求訪問url地址,然后得到html源代碼或者xml數(shù)據(jù)。
    2010-07-07
  • PHP實現(xiàn)的分頁類定義與用法示例

    PHP實現(xiàn)的分頁類定義與用法示例

    這篇文章主要介紹了PHP實現(xiàn)的分頁類定義與用法,結(jié)合具體實例形式分析了php封裝的分頁類常用操作及具體使用技巧,需要的朋友可以參考下
    2017-07-07
  • 很讓人受教的 提高php代碼質(zhì)量36計

    很讓人受教的 提高php代碼質(zhì)量36計

    很讓人受教的 提高php代碼質(zhì)量36計,需要的朋友可以參考下
    2012-09-09
  • php 數(shù)組二分法查找函數(shù)代碼

    php 數(shù)組二分法查找函數(shù)代碼

    search函數(shù) 其中$array為數(shù)組,$k為要找的值,$low為查找范圍的最小鍵值,$high為查找范圍的最大鍵值
    2010-02-02
  • PHP遍歷數(shù)組的幾種方法

    PHP遍歷數(shù)組的幾種方法

    這三種方法中效率最高的是使用foreach語句遍歷數(shù)組。從PHP4開始就引入了foreach結(jié)構(gòu),是PHP中專門為遍歷數(shù)組而設(shè)計的語句,推薦大家使用。先分別介紹這幾種方法
    2012-03-03

最新評論