Verification code class, PHP Verification code class
Familiar with the relevant image processing functions, simple Verification code class
1 //Code Class2 classValidatecode {3 Private $charset= ' abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789 ';//Random Effects4 Private $code;//Code5 Private $codelen= 4;//Code Length6 Private $width= 130;//width7 Private $heigth= 50;//Height8 Private $img;//Image Handle9 Private $font;//font FileTen Private $fontsize= 20;//Font Size One Private $fontcolor;//Font Color A - //the construct Initialization - Public function__construct () { the $this->font = Root_path. ' /font/elephant.ttf '; - } - - //create random code from $charset + Private functionCreatecode () { - $_len=strlen($this-charset); + for($i= 1;$i<=$this->codelen;$i++){ A $this->code. =$this->charset[Mt_rand(0,$_len)]; at } - } - - //Create Background - Private functionCreatebg () { - $this->img = Imagecreatetruecolor ($this->width,$this-heigth); in $_color= Imagecolorallocate ($this->img,Mt_rand(157,255),Mt_rand(157,255),Mt_rand(157,255)); -Imagefilledrectangle ($this->img,0,0,$this->width,$this->heigth,$_color); to } + - //Create Font the Private functionCreateFont () { * $_x=$this->width/$this-Codelen; $ for($i= 0;$i<$this->codelen;$i++){Panax Notoginseng $this->fontcolor = Imagecolorallocate ($this->img,Mt_rand(0,156),Mt_rand(0,156),Mt_rand(0,156)); -Imagettftext ($this->img,$this->fontsize,Mt_rand( -30,30),$_x*$i+Mt_rand(1,5),$this->heigth/1.4,$this->fontcolor,$this->font,$this->code[$i]); the } + } A the //Create Line,snowflake + Private functionCreateline () { - for($i= 0;$i<6;$i++){ $ $_color= Imagecolorallocate ($this->img,Mt_rand(0,156),Mt_rand(0,156),Mt_rand(0,156)); $Imageline ($this->img,Mt_rand(0,$this->width),Mt_rand(0,$this->heigth),Mt_rand(0,$this->width),Mt_rand(0,$this->heigth),$_color); - } - for($i= 0;$i<100;$i++){ the $_color= Imagecolorallocate ($this->img,Mt_rand(157,255),Mt_rand(157,255),Mt_rand(157,255)); -Imagestring ($this->img,Mt_rand(1, 5),Mt_rand(0,$this->width),Mt_rand(0,$this->heigth), ' * ',$_color);Wuyi } the } - Wu //Export Image - Private functionOutPut () { About Header(' Content-type:image/png '); $Imagepng ($this-img); -Imagedestroy ($this-img); - } - A //Display + Public functiondoimg () { the $this-CREATEBG (); - $this-Createcode (); $ $this-createline (); the $this-CreateFont (); the $this-OutPut (); the } the - //Get Code in Public functionGetCode () { the return Strtolower($this-code); the } About the } the
http://www.bkjia.com/PHPjc/1063511.html www.bkjia.com true http://www.bkjia.com/PHPjc/1063511.html techarticle Verification Code class, PHP verification code class familiar with the relevant image processing functions, simple Verification Code Class 1//code Class 2 class Validatecode {3 Private $charset = ' ABCDEFGHKMNPRSTUVWXYZABCD EFGHKMNP ...