php实现的验证码文件类实例

前端之家收集整理的这篇文章主要介绍了php实现的验证码文件类实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

PHP;"> mCheckCode = strtoupper(substr(md5(rand()),$this->mCheckCodeNum)); return $this->mCheckCode; }

/**

  • @brief 产生验证码图片
  • */
    private function CreateImage()
    {
    $this->mCheckImage = @imagecreate ($this->mCheckImageWidth,$this->mCheckImageHeight);
    imagecolorallocate ($this->mCheckImage,200,200);
    return $this->mCheckImage;
    }
    /**

  • @brief 设置图片的干扰像素
  • */
    private function SetDisturbColor()
    {
    for ($i=0;$i<=128;$i++)
    {
    $this->mDisturbColor = imagecolorallocate ($this->mCheckImage,rand(0,255),255));
    imagesetpixel($this->mCheckImage,rand(2,128),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,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程序设计有所帮助。

原文链接:https://www.f2er.com/php/21738.html

猜你在找的PHP相关文章