PHP implementation Click to refresh the verification code, PHP implementation Refresh Verification Code _php tutorial

Source: Internet
Author: User

PHP implementation Click to refresh the verification code, PHP implementation Refresh verification code


Verification code class file CreateImg.class.php

<?php class Validationcode {private $width, $height, $codenum; public $checkcode;  The generated verification code private $checkimage; Verification code Picture Private $disturbColor = ';   Interference pixel function __construct ($width = ' a ', $height = ' ", $codenum = ' 4 ') {$this->width= $width;   $this->height= $height; $this->codenum= $codenum;   } function Outimg () {//Output header $this->outfileheader ();    Generate Verification Code $this->createcode ();   Produce picture $this->createimage ();   Set the interference pixel $this->setdisturbcolor ();   Write the verification code on the picture $this->writecheckcodetoimage ();   Imagepng ($this->checkimage); Imagedestroy ($this->checkimage);  } Private Function Outfileheader () {Header ("Content-type:image/png");}  Private Function Createcode () {$this->checkcode = Strtoupper (substr (MD5 (rand ()), 0, $this->codenum));}   Private Function CreateImage () {$this->checkimage = @imagecreate ($this->width, $this->height);   $back = Imagecolorallocate ($this->checkimage,255,255,255); $border = Imagecolorallocate ($this->checkimage,0,0,0); Imagefilledrectangle ($this->checkimage,0,0, $this->width-1, $this->height-1, $back);  White Bottom Imagerectangle ($this->checkimage,0,0, $this->width-1, $this->height-1, $border); Black Border} Private function Setdisturbcolor () {for ($i =0; $i <=200; $i + +) {$this->disturbcolor = Imagecolorallo   Cate ($this->checkimage, rand (0,255), Rand (0,255), Rand (0,255));   Imagesetpixel ($this->checkimage,rand (2,128), Rand (2,38), $this->disturbcolor); }} Private Function Writecheckcodetoimage () {for ($i =0; $i <= $this->codenum; $i + +) {$BG _color = Imagecolorall   Ocate ($this->checkimage, rand (0,255), Rand (0,128), Rand (0,255));   $x = Floor ($this->width/$this->codenum) * $i;   $y = rand (0, $this->height-15);   Imagechar ($this->checkimage, rand (5,8), $x, $y, $this->checkcode[$i], $bg _color); }} function __destruct () {unset ($this->width, $this->height, $this->codenum);}}  ?>

Include File imgcode.php

<?php session_start (); Require_once (' CreateImg.class.php '); $image = new Validationcode (' + ', ' 4 ');  Picture length, width, number of characters $image->outimg (); $_session[' validationcode ' = $image->checkcode; Storage verification code to $_session?>

Front desk File demo.php

? php session_start (); $test = $_post[' test ']; $test = Strtoupper (Trim ($test)); $submit = $_post[' Submit ']; if (Isset ($submit)) {if ($test ==$_session[' Validationcode ') {   echo ' true ';} else {   echo ' false ';}}?>    Image 
 
          

The above is for everyone to introduce the PHP click Verification code can be refreshed all the code, I hope that everyone's learning has helped.

http://www.bkjia.com/PHPjc/1068820.html www.bkjia.com true http://www.bkjia.com/PHPjc/1068820.html techarticle PHP Implementation Click to refresh the verification code, PHP implementation Refresh code Verification code class file CreateImg.class.php PHP class Validationcode {Private $width, $height, $codenum; Public $checkcode; /...

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