PHP implementation of the code file class instance, _php tutorial

Source: Internet
Author: User

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-&GT;MCHeckimage); Imagedestroy ($this->mcheckimage);}} $c _check_code_image = new Ccheckcodefile ()//$c _check_code_image-&GT;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 ...

  • 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.