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 中的输出缓冲
Dec 21 PHP
理解和运用PHP中的多态性[译]
Aug 02 PHP
php修改NetBeans默认字体的大小
Jul 02 PHP
php stripslashes和addslashes的区别
Feb 03 PHP
php使用curl抓取qq空间的访客信息示例
Feb 28 PHP
php5.3 goto函数介绍和示例
Mar 21 PHP
PHP原生函数一定好吗?
Dec 08 PHP
Linux操作系统安装LAMP环境
Jun 26 PHP
Yii2中DropDownList简单用法示例
Jul 18 PHP
Yii框架弹出框功能示例
Jan 07 PHP
解决Laravel blade模板转义html标签的问题
Sep 03 PHP
ThinkPhP+Apache+PHPstorm整合框架流程图解
Nov 23 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二维数组排序方法(array_multisort usort)
2013/12/25 PHP
一漂亮的PHP图片验证码实例
2014/03/21 PHP
php+mysqli事务控制实现银行转账实例
2015/01/29 PHP
php单元测试phpunit入门实例教程
2017/11/17 PHP
JavaScript对象链式操作代码(jquery)
2010/07/04 Javascript
JavaScript的类型简单说明
2010/09/03 Javascript
jQuery动态地获取系统时间实现代码
2013/05/24 Javascript
js判断浏览器类型的方法
2013/08/07 Javascript
jsp网页搜索结果中实现选中一行使其高亮
2014/02/17 Javascript
详解AngularJS中module模块的导入导出
2015/12/10 Javascript
input点击后placeholder中的提示消息消失
2016/01/15 Javascript
Bootstrap实现下拉菜单效果
2016/04/29 Javascript
[原创]javascript typeof id==='string'?document.getElementById(id):id解释
2016/11/02 Javascript
Extjs表单输入框异步校验的插件实现方法
2017/03/20 Javascript
加载 vue 远程代码的组件实例详解
2017/11/20 Javascript
详解在Vue中使用TypeScript的一些思考(实践)
2018/07/06 Javascript
vue解决使用webpack打包后keep-alive不生效的方法
2018/09/01 Javascript
Element-UI中关于table表格的那些骚操作(小结)
2019/08/15 Javascript
python list转dict示例分享
2014/01/28 Python
对于Python的Django框架使用的一些实用建议
2015/04/03 Python
编写Python的web框架中的Model的教程
2015/04/29 Python
Python素数检测实例分析
2015/06/15 Python
python通过socket实现多个连接并实现ssh功能详解
2017/11/08 Python
Python数据结构之栈、队列的实现代码分享
2017/12/04 Python
我们为什么要减少Python中循环的使用
2019/07/10 Python
python使用pyecharts库画地图数据可视化的实现
2020/03/25 Python
django表单中的按钮获取数据的实例分析
2020/07/31 Python
详解python 支持向量机(SVM)算法
2020/09/18 Python
美国益智玩具购物网站:Fat Brain Toys
2017/11/03 全球购物
HomeAway的巴西品牌:Alugue Temporada
2018/04/10 全球购物
一套.net面试题及答案
2016/11/02 面试题
环保公益广告语
2014/03/13 职场文书
会计员岗位职责
2014/03/15 职场文书
旅游与环境专业求职信
2014/06/05 职场文书
党员学习正风肃纪思想汇报
2014/09/12 职场文书
我们的节日端午节活动总结
2015/02/11 职场文书