找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1645|回复: 0
打印 上一主题 下一主题

非常实用的php验证码类

[复制链接]

2560

主题

2560

帖子

7622

积分

论坛元老

Rank: 8Rank: 8

积分
7622
跳转到指定楼层
楼主
发表于 2018-2-14 05:36:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文实例为大家分享了php验证码类,供大家参考,具体内容如下
width=$width;
    $this->height=$height;
    $this->codeNum=$codeNum;
    $this->checkCode=$this->CreateCheckCode();
    $number=floor($width*$height/25);
    if ($number>240-$codeNum) {
      $this->disturbColorNum=240-$codeNum;
    }else{
      $this->disturbColorNum=$number;
    }
  }
   
  public function showImage($fontpath='') {
    //创建图像背景
    $this->Img_resouce();
    //var_dump($);
    //设置干扰元素
    $this->setDistructcolor();
    //向图像中随机画出文本
    $this->outputtext($fontpath);
    //输出图像
    $this->outputimage();
  }
  /**
   *
   *获取随机创建的验证码
   */
  public function getCheckCode(){
     
  }
  private function Img_resouce(){
    //创建一个真彩图像
    $this->($this->width,$this->height);
    //随机设置图像背景
    $backcolor=imagecolorallocate($this->,rand(225,255),rand(225,255),rand(225,255));
    //填充颜色
    imagefill($this->, 0, 0, $backcolor);
    //设置边框背景
    $border=imagecolorallocate($this->, 0,0,0);
    //画一个矩形
    imagerectangle($this->,0,0,$this->width-1,$this->height-1,$border);
  }
  private function setDistructcolor(){
    //绘画干扰点
    for ($i = 0; $i disturbColorNum; $i++) {
      
      imagesetpixel($this->, rand(1, $this->width-2), rand(1, $this->height-2), rand(0,255));
    }
     
    //绘画干扰线
    for ($j = 0; $j ,rand(0,255),rand(0,255),rand(0,255));
      imagearc($this->, rand(0,$this->width), rand(0,$this->height),
       rand(10, 225), rand(20, 150),
       55, 44, $linecolor);
    }
  }
  private function CreateCheckCode(){
    $code='23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ';
    $string='';
    for ($i = 0; $i codeNum; $i++) {
      
      $char=$code{rand(0, strlen($code)-1)};
      $string.=$char;
    }
    return $string;
  }
  private function outputtext($fontpath=''){
    for ($i = 0; $i codeNum; $i++) {
      $fontcolor=imagecolorallocate($this->, rand(0,128), rand(0, 128), rand(0, 128));
      if ($fontpath=='') {
         
         $fontsize=rand(3, 5);
         $x=floor($this->width/$this->codeNum)*$i+3;
         $y=rand(0, $this->height-20);
         imagechar($this->, $fontsize, $x, $y, $this->checkCode{$i}, $fontcolor);
    }else{
         $fontsize=rand(12, 16);
         $x=floor(($this->width-8)/$this->codeNum)*$i+8;
         $y=rand($fontsize, $this->height-15);
         imagettftext($this->,$fontsize,rand(-45,45),$x,$y,$fontcolor,fontpath,$this->checkCode{$i});
       }
    }
  }
  private function outputimage() {
     
    if (imagetypes() & ) {
      header("Content-type: image/gif");
      imagegif($this->);
    }else if(imagetypes() & ) {
      header("Content-type: image/jpeg");
      imagejpeg($this->);
    }else if(imagetypes() & ) {
      header("Content-type: image/png");
      imagepng($this->);
    }else {
      echo "HP不支持的类型";
    }
     
     
  }
  private function __destruct(){
     
    imagedestroy($this->);
  }
}
?>
以上就是本文的全部内容,希望对大家的学习有所帮助。
            
            
您可能感兴趣的文章:
  • PHP验证码类代码( 最新修改,完全定制化! )
  • 一个漂亮的php验证码类(分享)
  • 一个经典的PHP验证码类分享
  • PHP实现简单实用的验证码类
  • PHP编写的图片验证码类文件分享
  • PHP实现适用于自定义的验证码类
  • 一个简单安全的PHP验证码类 附调用方法
  • 一个简单安全的PHP验证码类、PHP验证码
  • 分享一个漂亮的php验证码类
  • PHP验证码类ValidateCode解析
  • 一个实用的php验证码类
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端