php实现加减法验证码代码


Posted in PHP onFebruary 14, 2014
<?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');
PHP 相关文章推荐
用mysql内存表来代替php session的类
Feb 01 PHP
PHP开发中的错误收集,不定期更新。
Feb 03 PHP
Zend的AutoLoad机制介绍
Sep 27 PHP
php数组合并array_merge()函数使用注意事项
Jun 19 PHP
jQuery+PHP+ajax实现微博加载更多内容列表功能
Jun 27 PHP
试用php中oci8扩展
Jun 18 PHP
Yii操作数据库实现动态获取表名的方法
Mar 29 PHP
CodeIgniter框架验证码类库文件与用法示例
Mar 18 PHP
PHP和MYSQL实现分页导航思路详解
Apr 11 PHP
PHP缓存工具XCache安装与使用方法详解
Apr 09 PHP
ThinkPHP框架使用redirect实现页面重定向的方法实例分析
Apr 12 PHP
laravel实现于语言包的完美切换方法
Sep 29 PHP
php实现mysql数据库操作类分享
Feb 14 #PHP
php将session放入memcached的设置方法
Feb 14 #PHP
smarty获得当前url的方法分享
Feb 14 #PHP
smarty模板中拼接字符串的方法
Feb 14 #PHP
php的sprintf函数的用法 控制浮点数格式
Feb 14 #PHP
PHP中$_FILES的使用方法及注意事项说明
Feb 14 #PHP
php $_SERVER windows系统与linux系统下的区别说明
Feb 14 #PHP
You might like
PHP文件上传实例详解!!!
2007/01/02 PHP
php函数指定默认值方法的小例子
2013/12/04 PHP
php上传图片生成缩略图(GD库)
2016/01/06 PHP
PHP实现文件上传功能实例代码
2017/05/18 PHP
PHPTree――php快速生成无限级分类
2018/03/30 PHP
jquery div 居中技巧应用介绍
2012/11/24 Javascript
将list转换为json失败的原因
2013/12/17 Javascript
Js获取下拉框选定项的值和文本的实现代码
2014/02/26 Javascript
JS运动基础框架实例分析
2015/03/03 Javascript
js实现简单的联动菜单效果
2015/08/19 Javascript
用JS实现图片轮播效果代码(一)
2016/06/26 Javascript
JS获取和修改元素样式的实例代码
2016/08/06 Javascript
强大的JavaScript响应式图表Chartist.js的使用
2017/09/13 Javascript
微信小程序App生命周期详解
2018/01/31 Javascript
jQuery实现聊天对话框
2020/02/08 jQuery
python通过scapy获取局域网所有主机mac地址示例
2014/05/04 Python
Python pickle类库介绍(对象序列化和反序列化)
2014/11/21 Python
Python itertools模块详解
2015/05/09 Python
Python基于PycURL实现POST的方法
2015/07/25 Python
Python爬虫爬取美剧网站的实现代码
2016/09/03 Python
python排序函数sort()与sorted()的区别
2018/09/18 Python
Python动态参数/命名空间/函数嵌套/global和nonlocal
2019/05/29 Python
python中使用ctypes调用so传参设置遇到的问题及解决方法
2019/06/19 Python
python覆盖写入,追加写入的实例
2019/06/26 Python
ZABBIX3.2使用python脚本实现监控报表的方法
2019/07/02 Python
PYTHON绘制雷达图代码实例
2019/10/15 Python
Python 线性回归分析以及评价指标详解
2020/04/02 Python
Ryderwear美国官网:澳大利亚高端健身训练装备品牌
2018/04/24 全球购物
Hotter Shoes美国官网:英国最受欢迎的舒适鞋
2018/08/02 全球购物
测绘工程个人的自我评价
2013/11/23 职场文书
个人自荐信
2013/12/05 职场文书
2014年药店店长工作总结
2014/11/17 职场文书
护士旷工检讨书
2015/08/15 职场文书
解决Python字典查找报Keyerror的问题
2021/05/26 Python
Arthas排查Kubernetes中应用频繁挂掉重启异常
2022/02/28 MySQL
python和Appium的移动端多设备自动化测试框架
2022/04/26 Python