首页 php教程 PHP源码 一个自己写的10以内的加减法验证码

一个自己写的10以内的加减法验证码

May 25, 2016 pm 05:07 PM

一个自己写的10以内的加减法验证码     

<?php
/*图片验证码文件,加减计算方式*/

class ImageCode{
	
	private $Jiashu  = 0;        //加数或者减数
	private $JianShu = 0;        //被加数或者被减数
	private $YunSuan = '';       //运算符
	private $DeShu   = 0;        //得数
	private $String  = '';       //字符串样式
	private $Img;                //图片对象
	private $Width   = 100;      //图片宽度
	private $Height  = 50;       //图片高度
	private $Ttf     = 'Num.ttf';//字体文件
	private $Session = 'code';   //Session变量
	
	
	
	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 -> Img, 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');
登录后复制

                                   

 以上就是一个自己写的10以内的加减法验证码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

两个点博物馆:邦格荒地地点指南
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

两个点博物馆:邦格荒地地点指南
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

谷歌浏览器不显示验证码图片怎么办?chrome浏览器不显示验证码? 谷歌浏览器不显示验证码图片怎么办?chrome浏览器不显示验证码? Mar 13, 2024 pm 08:55 PM

谷歌浏览器不显示验证码图片怎么办?chrome浏览器不显示验证码?

虚拟号码可以接收验证码吗 虚拟号码可以接收验证码吗 Jan 02, 2024 am 10:22 AM

虚拟号码可以接收验证码吗

手机为什么收不到验证码 手机为什么收不到验证码 Aug 17, 2023 pm 02:49 PM

手机为什么收不到验证码

PHP图片处理案例:如何实现图片的验证码功能 PHP图片处理案例:如何实现图片的验证码功能 Aug 17, 2023 pm 12:09 PM

PHP图片处理案例:如何实现图片的验证码功能

验证码拦不住机器人了!谷歌AI已能精准识别模糊文字,GPT-4则装瞎求人帮忙 验证码拦不住机器人了!谷歌AI已能精准识别模糊文字,GPT-4则装瞎求人帮忙 Apr 12, 2023 am 09:46 AM

验证码拦不住机器人了!谷歌AI已能精准识别模糊文字,GPT-4则装瞎求人帮忙

虚拟号码怎样接收验证码 虚拟号码怎样接收验证码 Oct 31, 2019 pm 04:52 PM

虚拟号码怎样接收验证码

用OCR技术,自动识别各种验证码,工具已开源 用OCR技术,自动识别各种验证码,工具已开源 May 25, 2023 am 10:07 AM

用OCR技术,自动识别各种验证码,工具已开源

PHP开发指南:实现验证码登录 PHP开发指南:实现验证码登录 Jul 01, 2023 am 09:27 AM

PHP开发指南:实现验证码登录

See all articles