千家信息网

如何使用php+js实现极验,拖动滑块验证码验证表单

发表于:2025-11-11 作者:千家信息网编辑
千家信息网最后更新 2025年11月11日,这篇文章给大家分享的是有关如何使用php+js实现极验,拖动滑块验证码验证表单的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。代码实现html文件
千家信息网最后更新 2025年11月11日如何使用php+js实现极验,拖动滑块验证码验证表单

这篇文章给大家分享的是有关如何使用php+js实现极验,拖动滑块验证码验证表单的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

  代码实现

  html文件

  

  

  

  

  

  

  极验滑块拖动验证码-码农社区-web视频分享网

  

  

  

  

  

  

  

  $TN.onsuccess(function(){

  //验证通过

  });

  

  php文件:check.php

  

  require_oncedirname(__FILE__).'/TnCode.class.php';

  $tn=newTnCode();

  if($tn->check()){

  $_SESSION['tncode_check']='ok';

  echo"ok";

  }else{

  $_SESSION['tncode_check']='error';

  echo"error";

  }

  ?>

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

  

  classTnCode

  {

  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();

  }

  }

  functionmake(){

  $this->_init();

  $this->_createSlide();

  $this->_createBg();

  $this->_merge();

  $this->_imgout();

  $this->_destroy();

  }

  functioncheck($offset=''){

  if(!$_SESSION['tncode_r']){

  returnfalse;

  }

  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;

  }

  privatefunction_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);

  }

  privatefunction_destroy(){

  imagedestroy($this->im);

  imagedestroy($this->im_fullbg);

  imagedestroy($this->im_bg);

  imagedestroy($this->im_slide);

  }

  privatefunction_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);

  }

  privatefunction_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

  }

  privatefunction_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);

  }

  privatefunction_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+js实现极验,拖动滑块验证码验证表单"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

验证 文件 表单 内容 图片 更多 篇文章 质量 不错 实用 代码 文章 核心 格式 看吧 知识 社区 视频 象素 超高 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 无尽的拉格朗日怎么查看登录过的服务器 数据库升级是提示列名无效 杭州恩牛网络技术公司 网络安全宣传防范个人信息泄露 论国家网络安全的重要性 api网关服务器配置 社交网络 移动网络安全 网络安全与管理内容 网络安全评估证明 美国软件开发就业 高中生关于网络安全的发言稿 搭建一个基因组数据库需要多少钱 学软件开发的职业兴趣 华为网络安全违规 软件开发核算方法 数据库安全方面的专业就业前景 网络安全张潇 魔兽世界角色转移服务器要多久 数据库关系模式设计 网信办网络技术局 ftp服务器的使用范围 csc网络安全调查报告 网络安全与管理内容 机关网络安全防护课件 网络安全保卫专业好吗 数据库多表连接查询相关代码 微信一直显示服务器正在运行 网络安全技术与硬件是什么 华为服务器通过mgmt装系统 网络安全与防火墙技术研究
0