色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:102日期:2022-09-10 10:56:06

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

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

極驗拖動動畫圖

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

代碼文件截圖

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

代碼實現

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>極驗滑塊拖動驗證碼-碼農社區-web視頻分享網</title> <script type='text/javascript' src='http://www.lshqa.cn/bcjs/tn_code.js?v=35'></script> <link rel='stylesheet' type='text/css' href='http://www.lshqa.cn/bcjs/style.css?v=27' rel='external nofollow' /><style type='text/css'></style></head><body style='text-align:center;'><div style='text-align: center;margin: 100px auto;'></div><script type='text/javascript'>$TN.onsuccess(function(){//驗證通過});</script>

php文件:check.php

<?phprequire_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

<?phpclass 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’)){//優先webp格式,超高壓縮率 $type = ’webp’; $quality = 40;//圖片質量 0-100 }else{ $type = ’png’; $quality = 7;//圖片質量 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); }}?>

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

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

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

標簽: PHP
相關文章:
主站蜘蛛池模板: 久久免费精品国产72精品剧情 | 18在线| 99久久国产综合精品1尤物 | 亚洲成人在线视频网站 | 国产成人十八黄网片 | 日韩欧美在线观看视频 | 毛片a级三毛片免费播放 | 日日摸人人看97人人澡 | 欧美一区二区在线 | 美国一级毛片片aa成人 | 亚洲日本va | 成人丁香乱小说 | 韩国毛片免费 | 欧美一区二区三区免费不卡 | 欧美三级aaa | 成人伊人| 午夜香蕉网 | 久草青草 | 精品久久久久久中文字幕 | 天天综合色一区二区三区 | 日本欧美久久久久免费播放网 | 久草在线中文最新视频 | 久久久久国产一级毛片高清板 | 免费a级毛片视频 | 亚洲精品资源网在线观看 | 美国毛片基地a级e片 | 成人aaaa| 免费一级做a爰片性色毛片 免费一极毛片 | 七七国产福利在线二区 | 伊人久热这里只有精品视频99 | 欧美一区视频在线 | 91久久综合九色综合欧美98 | 小毛片在线观看 | 高清在线亚洲精品国产二区 | 黄色成人在线观看 | 亚洲图片视频在线 | 亚洲一级免费视频 | 亚洲欧美日韩国产精品 | 亚洲国产天堂久久精品网 | 亚洲成年人免费网站 | 亚洲欧美日韩精品久久亚洲区色播 |