This article mainly introduces the PHP implementation of the addition and subtraction verification code code, you can use the addition and subtraction within 10 to generate pictures, the need for friends can refer to the following
Code is as follows: <?php/* Picture Verification code file, add and subtract calculation mode/ class imagecode{ private $Jiashu = 0 &NB Sp //addends or meiotic private $JianShu = 0; //summand or private $YunSuan = '; //operator private $DeShu = 0; // private $String = '; //String style private $Img; //Picture object private $Width = 100; //picture width private $Height = 50; //Picture height private $Ttf = ' num.ttf ';//font file private $Session = ' code '; //session variable private function Jiashu () { header (' content-type:image/png '); $this-> Ji Ashu = rand (1, 10); $this-> Jianshu = rand (1, 10); $this-> yunsuan= $this-> jiashu > $this-> jianshu? '-' : '+'; $this-> Deshu = $this; Jiashu > $this-> jianshu? $this-> jiashu-$this-> jianshu: $this-> Jiashu + $this-> Jianshu; &NBSP} public function show ($W = $H = +, $T = ' Num.ttf ', $Code = ' Code ') { $this-> Jiashu ( ); $this-> String = $this-> Jiashu. $this-> Yunsuan. $this-> Jianshu. '= ? '; $this-> Width = $W; $this-> Height = $H; $this-> Ttf = $T; $this-> session= $Code; Session_Start (); $_session[$this-> Session] = $this-> Deshu; $this-> Images (); &NBSP} private function Images () { $this-> Img = imagecreate ($this-> Width, $this-> Height ); $background _color = imagecolorallocate ($this-> Img, 255, 255, 255); Imagecolortransparent ($this-> Img, $background _color); imagettftext ($this-> img, 0, 1, imagecolorallocate ($this-> img, 0, 0, 0), $th Is -> TTF, $this-> String); $this-> echoimages (); &NBSP} private function echoimages () { imagepng ($this-> img); Imagedestroy ($this-> img) ; &NBSP} } $ImageCode = new Imagecode; $ImageCode-> Show (130, the ' Num.ttf ', ' Code ');