Home >php教程 >php手册 >PHP简单验证码类

PHP简单验证码类

WBOY
WBOYOriginal
2016-06-06 19:56:451350browse

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 header ("Content-type: image/jpeg"); $code=imagejpeg($this-im); }elseif (function_exists("imagegif")) { header("Content-type: image/gif"); $code=imagegif($this-im); } imagedestroy($this

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

 

  header ("Content-type: image/jpeg");

  $code=imagejpeg($this->im);

  }elseif (function_exists("imagegif"))

  {

  header("Content-type: image/gif");

  $code=imagegif($this->im);

  }

  imagedestroy($this->im);

  return $code;

  }

  /**

  * 检查验证码

  * @param $code

  * @return bool

  */

  public function checkCode($code) {

  session_start();

  $secode=explode(',', $_SESSION['initphp_code']);

  $time=time();

  //检查时间是否过期

  if($secode[0]>$time||$time-$secode[0]>$this->time)

  {

  return false;

  }

  //验证码密钥 双md5 后是否一致

  if($secode[1]md5(md5($code.'initphpYzmsy'.$secode[0]))){

  return false;

  }

  //检查验证码字符串是否一致

  if($code||$code$secode[2])

  {

  return false;

  }

  return true;

  }

  /*随机扭曲*/

  public function setWarping(){

  $rgb=array();

  $direct=rand(0,1);

  $width = imagesx($this->im);

  $height = imagesy($this->im);

  $level=$width /20;

  for($j = 0;$j

  for($i = 0;$i

  $rgb[$i] = imagecolorat($this->im, $i , $j);

  }

  for($i = 0;$i

  $r = sin($j / $height * 2 * M_PI - M_PI * 0.5) * ($direct ? $level : -$level);

  imagesetpixel($this->im, $i + $r , $j , $rgb[$i]);

  }

  }

  }

  }

  ?>

  效果:

   PHP简单验证码类

  [1] [2] 

PHP简单验证码类

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn