PHP implementation for custom verification code class, PHP verification code
This example for everyone to share the PHP verification code class, the use of objects to achieve the verification code class, for your reference, the specific content as follows
<?php/* To the license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */class image{Private $img, public $width = $height, public $code, public $code _len = 4, public $code _s TR = "329832983DSDSKDSLKQWEWQ2LKFDSFSDJFDSFDSJWLKFJ93290KFDSKJFDSOIDSLK"; Public $BG _color = ' #DCDCDC '; Public $font _size = 16; Public $font = ' Font.ttf '; Public $font _color = ' #000000 '; Create a CAPTCHA hungry character create public function Create_code () {$code = '; for ($i =0; $i < $this->code_len; $i + +) {$code. = $this->code_str[mt_rand (0, strlen ($this->code_str)-1)];} return $this->code = $code; }//Output image Public Function GetImage () {$w = $this->width; $h = $this->height; $BG _color = $this->bg_color; $img = Imagecreatetruecolor ($w, $h); $BG _color = imagecolorallocate ($img, Hexdec (substr ($BG _color, Up)), Hexdec (substr ($BG _color, 3,2)), Hexdec (substr ($ Bg_color, 5,2)); IMagefill ($img, 0, 0, $bg _color); $this->img = $img; $this->create_font (); $this->create_pix (); $this->show_code (); }//write Verification code Public Function Create_font () {$this->create_code (); $color = $this->font_color; $font _color = imagecolorallocate ($this->img, Hexdec (substr ($color, up)), Hexdec (substr ($color, 3,2)), Hexdec ( substr ($color, 5,2))); $x = $this->width/$this->code_len; for ($i =0; $i < $this->code_len; $i + +) {$txt _color = imagecolorallocate ($this->img, Mt_rand (0,100), Mt_rand (0, Mt_rand (0, 200)); Imagettftext ($this->img, $this->font_size, Mt_rand ( -30,), $x * $i +mt_rand (3, 6), Mt_rand ($this->height/1.2 , $this->height), $txt _color, $this->font, $this->code[$i]); Imagestring ($this->img, $this->font_size, $x * $i +mt_rand (3, 6), Mt_rand (0, $this->HEIGHT/4), $this- code[$i], $font _color); } $this->font_color = $font _color; }//Draw interference line public function Create_pix () {$pix _color= $this->font_color; FoR ($i =0; $i <100; $i + +) {Imagesetpixel ($this->img, Mt_rand (0, $this->width), Mt_rand (0, $this->height), $pix _color); } for ($j =0; $j <4; $j + +) {imagesetthickness ($this->img, Mt_rand (1, 2)); Imageline ($this->img, Mt_rand (0, $this->width), Mt_rand (0, $this->height), Mt_rand (0, $this->width), Mt_ Rand (0, $this->height), $pix _color); }}//Get the CAPTCHA public Function GetCode () {return strtoupper ($this->code);} Output Verification Code Private Function Show_code () {Header ("content-type:image/png"); Imagepng ($this->img); Imagedestroy ($this->img); }}
:
Wonderful topic Sharing: ASP. PHP Verification Code Daquan Java Verification Code Daquan
The above is the use of the object to write the entire content of the verification code class, I hope that you learn PHP programming help.
http://www.bkjia.com/PHPjc/1136637.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136637.html techarticle PHP implementation for the custom code class, PHP verification code example for everyone to share the PHP verification code class, the use of objects to achieve the verification code class, for your reference, the specific content as follows ...