Very useful PHP Verification code class, very useful PHP code _php tutorial

Source: Internet
Author: User

Very useful PHP Verification code class, very useful PHP verification code


This example for everyone to share the PHP verification code class, for your reference, the specific content as follows

<?php/** * * @author Administrator * * */class validatecode{private $width;   Private $height;   Private $codeNum;   Private $img _resouce;   Private $disturbColorNum;      Private $checkCode;     function __construct ($width =80, $height =20, $codeNum =4) {$this->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 = ") {//Create image Background $this->img_resouce ();     Var_dump ($img _resouce);     Set the interference element $this->setdistructcolor ();     Randomly draw text $this->outputtext ($fontpath) into the image;   Output Image $this->outputimage (); /** * * Get randomly created verification code */Public Function Getcheckcode () {} private Function Img_resouce () {//Create a true Color Image $this->img_resouce=imagecreatetruecolor ($this->width, $this->height);     Randomly set image background $backcolor =imagecolorallocate ($this->img_resouce,rand (225,255), Rand (225,255), Rand (225,255));     Fill Color Imagefill ($this->img_resouce, 0, 0, $backcolor);     Set Border background $border =imagecolorallocate ($this->img_resouce, 0,0,0);   Draw a rectangular imagerectangle ($this->img_resouce,0,0, $this->width-1, $this->height-1, $border);              } Private Function Setdistructcolor () {//Painting interference point for ($i = 0; $i < $this->disturbcolornum; $i + +) {     Imagesetpixel ($this->img_resouce, rand (1, $this->width-2), rand (1, $this->height-2), rand (0,255)); }//Painting interference line for ($j = 0; $j <3; $j + +) {$linecolor =imagecolorallocate ($this->img_resouce,rand (0,255       ), Rand (0,255), Rand (0,255));        Imagearc ($this->img_resouce, rand (0, $this->width), rand (0, $this->height), Rand (Ten, 225), Rand (20, 150),     , $linecolor); }} Private Function CreatechecKcode () {$code = ' 23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ ';     $string = ";       for ($i = 0; $i < $this->codenum; $i + +) {$char = $code {rand (0, strlen ($code)-1)};     $string. = $char;   } return $string; } Private Function Outputtext ($fontpath = ") {for ($i = 0; $i < $this->codenum; $i + +) {$fontcolor =imagec       Olorallocate ($this->img_resouce, rand (0,128), rand (0, $), 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->img_resouce, $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->img_resouce, $fontsize, Rand ( -45,45), $x, $y, $fontcolor, Fontpath, $this->checkcode{$i}); }     }} Private Function Outputimage () {if (Imagetypes () & Img_gif) {header ("Content-type:image       /gif ");     Imagegif ($this->img_resouce);       }else if (Imagetypes () & Img_jpeg) {header ("content-type:image/jpeg");     Imagejpeg ($this->img_resouce);       }else if (Imagetypes () & Img_png) {header ("content-type:image/png");     Imagepng ($this->img_resouce);     }else {echo "PHP unsupported Type";   }} Private Function __destruct () {Imagedestroy ($this->img_resouce); }}?>

The above is the whole content of this article, I hope that everyone's study has helped.

http://www.bkjia.com/PHPjc/1127899.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127899.html techarticle Very useful PHP verification code class, very useful PHP verification code example for everyone to share the PHP verification code class, for your reference, specific content as follows PHP/** * * @author Administrator * * ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.