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 相关文章推荐
php数组函数序列之array_key_exists() - 查找数组键名是否存在
Oct 29 PHP
php生成局部唯一识别码LUID的代码
Oct 06 PHP
php使用Jpgraph绘制柱形图的方法
Jun 10 PHP
PHP截取IE浏览器并缩小原图的方法
Mar 04 PHP
php中实现进程锁与多进程的方法
Sep 18 PHP
AES加解密在php接口请求过程中的应用示例
Oct 26 PHP
php获取今日开始时间和结束时间的方法
Feb 27 PHP
用PHP去掉文件头的Unicode签名(BOM)方法
Jun 22 PHP
tp5(thinkPHP5)框架连接数据库的方法示例
Dec 24 PHP
php项目中类的自动加载实例讲解
Sep 12 PHP
laravel框架创建授权策略实例分析
Nov 22 PHP
PHP架构及原理知识点详解
Dec 22 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
在Windows中安装Apache2和PHP4的权威指南
2006/10/09 PHP
基于HBase Thrift接口的一些使用问题及相关注意事项的详解
2013/06/03 PHP
ThinkPHP整合datatables实现服务端分页的示例代码
2018/02/10 PHP
PHP封装的mysqli数据库操作类示例
2019/02/16 PHP
javascript 文档的编码问题解决
2009/03/01 Javascript
Javascript的匿名函数小结
2009/12/31 Javascript
jQuery EasyUI API 中文文档 - Documentation 文档
2011/09/29 Javascript
jquery选择器之层级过滤选择器详解
2014/01/27 Javascript
使用text方法获取Html元素文本信息示例
2014/09/01 Javascript
JS排序方法(sort,bubble,select,insert)代码汇总
2016/01/30 Javascript
AngularJS表单验证中级篇(3)
2016/09/28 Javascript
微信小程序之小豆瓣图书实例
2016/11/30 Javascript
微信小程序 require机制详解及实例代码
2016/12/14 Javascript
canvas实现绘制吃豆鱼效果
2017/01/12 Javascript
微信小程序本作用域下调用全局JS详解及实例
2017/02/22 Javascript
vue 如何添加全局函数或全局变量以及单页面的title设置总结
2017/06/01 Javascript
vue使用keep-alive实现数据缓存不刷新
2017/10/21 Javascript
jQuery+ajax读取json数据并按照价格排序示例
2018/03/28 jQuery
JavaScript 变量,数据类型基础实例详解【变量、字符串、数组、对象等】
2020/01/04 Javascript
详解vue v-model
2020/08/31 Javascript
[09:33]2015国际邀请赛第四日TOP10
2015/08/08 DOTA
python将字符串转换成数组的方法
2015/04/29 Python
Python中函数参数匹配模型详解
2019/06/09 Python
Python实现Word表格转成Excel表格的示例代码
2020/04/16 Python
Django中日期时间型字段进行年月日时分秒分组统计
2020/11/27 Python
python反扒机制的5种解决方法
2021/02/06 Python
《故乡》教学反思
2014/04/10 职场文书
离婚协议书怎么写2014
2014/09/30 职场文书
运动会广播稿20字
2015/08/19 职场文书
2015年乡镇组织委员工作总结
2015/10/23 职场文书
考研经验交流会策划书
2015/11/02 职场文书
高中物理教学反思
2016/02/19 职场文书
财产分割协议书
2016/03/22 职场文书
MySQL 覆盖索引的优点
2021/05/19 MySQL
教你使用vscode 搭建react-native开发环境
2021/07/07 Javascript
python 使用tkinter与messagebox写界面和弹窗
2022/03/20 Python