Verification code file class instance _php techniques implemented in PHP

Source: Internet
Author: User

The example in this article describes the authentication code file class for the PHP implementation. Share to everyone for your reference. as follows:

<?php/** * @file * @version 1.0 * @author Net Sea Prodigal Son * @brief Verification code File Class * */Class Ccheckcodefile {//Verify code number private $mCheck
Codenum = 4;
The resulting verification code private $mCheckCode = ';
The picture of the verification code private $mCheckImage = ';
Interference pixel private $mDisturbColor = ';
The picture width of the verification code is private $mCheckImageWidth = ' 80 ';
The picture width of the verification code is private $mCheckImageHeight = ' 20 '; 
/** * * * @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 a CAPTCHA picture */Private Function createimage () {$this->mcheckimage = @imagecreate ($this->mchecki
 Magewidth, $this->mcheckimageheight);
  Imagecolorallocate ($this->mcheckimage, 200, 200, 200);
return $this->mcheckimage; /** * * * @brief Set the image's jamming pixel */private Function Setdisturbcolor () {for ($i =0; $i <=128; $i + +) {$this->mdistur Bcolor = ImagEcolorallocate ($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 verification code picture * * @param $width Wide * * * @param $height High * */Public Function SETCHECKIMAGEWH ($width, $he ight) {if ($width = = ' | |
 $height = = ") return false;
 $this->mcheckimagewidth = $width;
 $this->mcheckimageheight = $height;
return true; /** * * @brief on the verification code picture one by one to draw the verification code */Private Function Writecheckcodetoimage () {for ($i =0; $i <= $this->mcheckcodenu
  m; $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-&GT;SETCHECKIMAGEWH (100,50);

 Set the size of the display verification code picture $c _check_code_image->outcheckimage ();?>

I hope this article will help you with your PHP programming.

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.