Php implements addition and subtraction verification code. Copy the code as follows :? Php * image verification code file. addition and subtraction calculation method * classImageCode {private $ Jiashu0; addition or subtraction private $ JianShu0; addition or subtraction
The code is as follows:
/* Image verification code file, plus or minus calculation method */
Class ImageCode {
Private $ Jiashu = 0; // addition or subtraction
Private $ JianShu = 0; // add number or subtrahend
Private $ YunSuan = ''; // operator
Private $ DeShu = 0; // number
Private $ String = ''; // String style
Private $ Img; // image object
Private $ Width = 100; // image Width
Private $ Height = 50; // Image Height
Private $ Ttf = 'Num. ttf'; // font file
Private $ Session = 'code'; // Session variable
Private function JiaShu (){
Header ('content-type: image/png ');
$ This-> Jiashu = 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;
}
Public function Show ($ W = 100, $ H = 50, $ 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 ();
}
Private function Images (){
$ This-> Img = imagecreate ($ this-> Width, $ this-> Height );
$ Background_color = imagecolorallocate ($ this-> image, 255,255,255 );
Imagecolortransparent ($ this-> Img, $ background_color );
Imagettftext ($ this-> Img, 14, 0, 1, 20, imagecolorallocate ($ this-> Img, 0, 0, 0), $ this-> Ttf, $ this-> String );
$ This-> EchoImages ();
}
Private function EchoImages (){
Imagepng ($ this-> Img );
Imagedestroy ($ this-> Img );
}
}
$ ImageCode = new ImageCode;
$ ImageCode-> Show (130, 35, 'Num. ttf', 'code ');
The http://www.bkjia.com/PHPjc/825253.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825253.htmlTechArticle code is as follows :? Php/* image verification code file, plus or minus calculation method */class ImageCode {private $ Jiashu = 0; // add or subtract private $ JianShu = 0; // add or subtract...