相思资源网 Design By www.200059.com

本文实例讲述了php实现的验证码文件类。分享给大家供大家参考。具体如下:

<"Content-type: image/png");
}
/**
*
* @brief  产生验证码
*
*/
private function CreateCheckCode()
{
 $this->mCheckCode = strtoupper(substr(md5(rand()),0,$this->mCheckCodeNum));
  return $this->mCheckCode;
}
 
/**
*
* @brief  产生验证码图片
*
*/
private function CreateImage()
{
 $this->mCheckImage = @imagecreate ($this->mCheckImageWidth,$this->mCheckImageHeight);
 imagecolorallocate ($this->mCheckImage, 200, 200, 200);
  return $this->mCheckImage;
}
/**
*
* @brief  设置图片的干扰像素
*
*/
private function SetDisturbColor()
{
  for ($i=0;$i<=128;$i++)
  {
  $this->mDisturbColor = imagecolorallocate ($this->mCheckImage, rand(0,255), rand(0,255), rand(0,255));
  imagesetpixel($this->mCheckImage,rand(2,128),rand(2,38),$this->mDisturbColor);
  }
}
/**
*
* @brief  设置验证码图片的大小
*
* @param  $width  宽
*
* @param  $height 高
*
*/
public function SetCheckImageWH($width,$height)
{
 if($width==''||$height=='')return false;
 $this->mCheckImageWidth = $width;
 $this->mCheckImageHeight = $height;
 return true;
}
/**
*
* @brief  在验证码图片上逐个画上验证码
*
*/
private function WriteCheckCodeToImage()
{
  for ($i=0;$i<=$this->mCheckCodeNum;$i++)
  {
  $bg_color = imagecolorallocate ($this->mCheckImage, rand(0,255), rand(0,128), rand(0,255));
  $x = floor($this->mCheckImageWidth/$this->mCheckCodeNum)*$i;
  $y = rand(0,$this->mCheckImageHeight-15);
  imagechar ($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
  }
}
/**
*
* @brief  输出验证码图片
*
*/
public function OutCheckImage()
{
 $this ->OutFileHeader();
 $this ->CreateCheckCode();
 $this ->CreateImage();
 $this ->SetDisturbColor();
 $this ->WriteCheckCodeToImage();
 imagepng($this->mCheckImage);
 imagedestroy($this->mCheckImage);
}
}
$c_check_code_image = new CCheckCodeFile();
//$c_check_code_image ->SetCheckImageWH(100,50);
//设置显示验证码图片的尺寸
$c_check_code_image ->OutCheckImage();
?>

希望本文所述对大家的php程序设计有所帮助。

标签:
php,验证码,文件类

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“php实现的验证码文件类实例”

暂无php实现的验证码文件类实例的评论...