PHP implementation of the Captcha file class instance,
This article describes the PHP implementation of the code file class. Share to everyone for your reference. Specific as follows:
<?php/*** @file * @version 1.0* @author Net Prodigal * @brief Verification code file class **/class ccheckcodefile{//authentication code BITS Private $mCheckCodeNum = 4; The generated verification code private $mCheckCode = ";//The picture of the verification code private $mCheckImage =";//interference pixel private $mDisturbColor = ";//The picture width of the captcha is private $ Mcheckimagewidth = ' 80 ';//The image width of the verification code is private $mCheckImageHeight = ' ";/**** @brief output head **/private function Outfileheader () {Header ("Content-type:image/png");} /**** @brief Generate Verification Code **/private function Createcheckcode () {$this->mcheckcode = Strtoupper (substr (MD5 (rand ()), 0,$ This->mcheckcodenum)); return $this->mcheckcode;} /**** @brief generate Captcha picture **/private function CreateImage () {$this->mcheckimage = @imagecreate ($this Mcheckimagewidth, $this->mcheckimageheight); Imagecolorallocate ($this->mcheckimage, 200, 200, 200); return $this->mcheckimage;} /**** @brief set Image interference pixels **/private function Setdisturbcolor () {for ($i =0; $i <=128; $i + +) {$this->mdisturbcolor = IM Agecolorallocate ($this->mcheckimage, rand (0,255), rand (0,255), Rand (0,255)); Imagesetpixel ($this->mcheckimage,rand (2,128), Rand (2,38), $this->mdisturbcolor); }}/**** @brief Set the size of the CAPTCHA picture * * @param $width Width * * @param $height high **/public function Setcheckimagewh ($width, $height) {if ($ width== ' | | $height = = ") return false; $this->mcheckimagewidth = $width; $this->mcheckimageheight = $height; return true;} /**** @brief on the verification code picture one by one on the verification code **/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 Output Verification code picture **/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);//Set the size of the display captcha picture $c_ Check_code_image->outcheckimage ();? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1019058.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019058.html techarticle PHP Implementation of the verification code file class instance, this article describes the PHP implementation of the verification code file class. Share to everyone for your reference. Specific as follows: php/*** @file * @version 1.0* @author net ...