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