Using PHP to implement add-subtract verification code

Source: Internet
Author: User
This article mainly introduces the PHP implementation of the code to add and subtract codes, you can use the addition and subtraction within 10 to generate pictures, the need for friends can refer to the following

<?php/* Image Verification code file, add and subtract calculation method */class imagecode{Private $Jiashu = 0;        Addend or meiosis $JianShu = 0;       Summand or $YunSuan = ';        operator private $DeShu = 0;       Private $String = ';                string style private $Img;      Picture Object Private $Width = 100;       Picture 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); Jianshu, Jiashu > $this, yunsuan= $this, $this  '-' : '+'; $this Deshu = Jiashu > $this, $this, Jianshu? jiashu-$this, $this, Jianshu: $this, Jiashu + $this-Jianshu;  Public Function Show ($W = $H =, $T = ' Num.ttf ', $Code = ' Code ') {$this-Jiashu (); $this, String = $this, Jiashu. Yunsuan, $this. Jianshu, $this. '= ?  '; $this Width = $W; $this, Height = $H;  $this, TTF = $T;  $this-session= $Code;  Session_Start ();  $_session[$this, SESSION] = Deshu, $this; $this-Images ();  } Private Function Images () {$this, Img = Imagecreate ($this, Width, $this, Height);  $background _color = imagecolorallocate ($this, IMG, 255, 255, 255);        Imagecolortransparent (Img $this, $background _color); Imagettftext ($this, IMG, 0, 1, imagecolorallocate ($this, IMG, 0, 0, 0), $this, TTF, $this, St  Ring); $this-Echoimages ();  } Private Function Echoimages () {imagepng ($this-IMG); Imagedestroy ($this, IMG); }} $ImageCode = new Imagecode; Show (Num.ttf, ' Code '), $ImageCode

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.