Code of the addition/subtraction Verification Code implemented by php

Source: Internet
Author: User

Code of the addition/subtraction Verification Code implemented by php

This article mainly introduces the code of the addition and subtraction Verification Code implemented by php. You can use the addition and subtraction codes of less than 10 to generate images. For more information, see

The Code is as follows:

<? Php

/* 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 ');

 

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.