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定时删除文件夹下文件(清理缓存文件)
Jan 23 PHP
destoon实现会员商铺中指定会员或会员组投放广告的方法
Aug 21 PHP
在Ubuntu 14.04上部署 PHP 环境及 WordPress
Sep 02 PHP
ThinkPHP采用原生query实现关联查询left join实例
Dec 02 PHP
PHP解密Unicode及Escape加密字符串
May 17 PHP
学习php设计模式 php实现观察者模式(Observer)
Dec 09 PHP
Symfony模板的快捷变量用法实例
Mar 17 PHP
ThinkPHP使用getlist方法实现数据搜索功能示例
May 08 PHP
PHP给前端返回一个JSON对象的实例讲解
May 31 PHP
php将从数据库中获得的数据转换成json格式并输出的方法
Aug 21 PHP
PHP进阶学习之命名空间基本用法分析
Jun 18 PHP
Laravel5.1 框架表单验证操作实例详解
Jan 07 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 calender(日历)二个版本代码示例(解决2038问题)
2013/12/24 PHP
PHP连接SQLServer2005方法及代码
2013/12/26 PHP
ThinkPHP行为扩展Behavior应用实例详解
2014/07/22 PHP
最新最全PHP生成制作验证码代码详解(推荐)
2016/06/12 PHP
javascript下操作css的float属性的特殊写法
2007/08/22 Javascript
基于Jquery实现的一个图片滚动切换
2012/06/21 Javascript
javascript获取网页中指定节点的父节点、子节点的方法小结
2013/04/24 Javascript
javascript中打印当前的时间实现思路及代码
2013/12/18 Javascript
JS+CSS实现感应鼠标渐变显示DIV层的方法
2015/02/20 Javascript
jquery获取及设置outerhtml的方法
2015/03/09 Javascript
在浏览器中打开或关闭JavaScript的方法
2015/06/03 Javascript
在Ubuntu系统上安装Ghost博客平台的教程
2015/06/17 Javascript
关注jquery技巧提高jquery技能(前端开发必学)
2015/11/02 Javascript
jQuery实现验证年龄简单思路
2016/02/24 Javascript
IE下JS保存图片的简单实例
2016/07/15 Javascript
Vue.js实战之组件的进阶
2017/04/04 Javascript
浅谈微信小程序之官方UI框架we-ui使用教程
2018/08/20 Javascript
[30:37]【全国守擂赛】第三周擂主赛 Dark Knight vs. Leopard Gaming
2020/05/04 DOTA
centos系统升级python 2.7.3
2014/07/03 Python
理解Python垃圾回收机制
2016/02/12 Python
Python实现字典依据value排序
2016/02/24 Python
Python实现打印螺旋矩阵功能的方法
2017/11/21 Python
python中logging包的使用总结
2018/02/28 Python
Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码
2018/09/14 Python
python 美化输出信息的实例
2018/10/15 Python
python里dict变成list实例方法
2019/06/26 Python
python爬虫爬取图片的简单代码
2021/01/18 Python
css3media响应式布局实例
2016/07/08 HTML / CSS
记一次高分屏下canvas模糊问题
2020/02/17 HTML / CSS
唤醒头发毛囊的秘密武器:Grow Gorgeous
2016/08/28 全球购物
GUESS德国官网:美国牛仔服装品牌
2017/02/14 全球购物
亚马逊新加坡官方网站:Amazon.sg
2020/03/25 全球购物
公司成立感言
2014/01/11 职场文书
会议接待欢迎词
2014/01/12 职场文书
经济信息系毕业生自荐信
2014/06/02 职场文书
Python Pandas常用函数方法总结
2021/06/15 Python