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+mysql留言本源码
Nov 11 PHP
修改php.ini不生效问题解决方法(上传大于8M的文件)
Jun 14 PHP
PHP图片裁剪函数(保持图像不变形)
May 04 PHP
利用PHP函数计算中英文字符串长度的方法
Nov 11 PHP
php实现session自定义会话处理器的方法
Jan 27 PHP
PHP通过串口实现发送短信
Jul 08 PHP
学习php设计模式 php实现建造者模式
Dec 07 PHP
PHP模板引擎Smarty之配置文件在模板变量中的使用方法示例
Apr 11 PHP
PHP flush 函数使用注意事项
Aug 26 PHP
基于CI(CodeIgniter)框架实现购物车功能的方法
Apr 09 PHP
tp5(thinkPHP5框架)captcha验证码配置及验证操作示例
May 28 PHP
php双向队列实例讲解
Nov 17 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&amp;mysql(六)
2006/10/09 PHP
php生成excel列序号代码实例
2013/12/24 PHP
基于laravel制作APP接口(API)
2016/03/15 PHP
php在windows环境下获得cpu内存实时使用率(推荐)
2018/02/08 PHP
javascript 函数调用的对象和方法
2010/07/01 Javascript
给jQuery方法添加回调函数一款插件的应用
2013/01/21 Javascript
Blocksit插件实现瀑布流数据无限( 异步)加载
2014/06/20 Javascript
jquery实现类似淘宝星星评分功能实例
2014/09/12 Javascript
jQuery中ajax的load()方法用法实例
2014/12/26 Javascript
JavaScript动态修改背景颜色的方法
2015/04/16 Javascript
移动端js触摸事件详解
2016/09/18 Javascript
jquery获取点击控件的绝对位置简单实例
2016/10/13 Javascript
vue开发心得和技巧分享
2016/10/27 Javascript
详解vue2.0监听属性的使用心得及搭配计算属性的使用
2018/07/18 Javascript
react native 原生模块桥接的简单说明小结
2019/02/26 Javascript
Vue在 Nuxt.js 中重定向 404 页面的方法
2019/04/23 Javascript
vue使用@scroll监听滚动事件时,@scroll无效问题的解决方法详解
2019/10/15 Javascript
[42:20]Winstrike vs VGJ.S 2018国际邀请赛淘汰赛BO3 第二场 8.23
2018/08/24 DOTA
Python中的MongoDB基本操作:连接、查询实例
2015/02/13 Python
Python实现快速多线程ping的方法
2015/07/15 Python
Python操作Excel之xlsx文件
2017/03/24 Python
Python图像处理之gif动态图的解析与合成操作详解
2018/12/30 Python
python 利用文件锁单例执行脚本的方法
2019/02/19 Python
使用PyTorch将文件夹下的图片分为训练集和验证集实例
2020/01/08 Python
Tory Burch英国官方网站:美国时尚生活品牌
2017/12/06 全球购物
广告学毕业生求职信
2014/01/30 职场文书
三提三创主题教育活动查摆整改措施
2014/10/25 职场文书
孕妇离婚协议书范本
2014/11/20 职场文书
2015年除四害工作总结
2015/07/23 职场文书
2016新教师培训心得体会范文
2016/01/08 职场文书
八年级语文教学反思
2016/03/03 职场文书
祝福语集锦:朋友新店开业祝福语
2019/12/10 职场文书
Python初学者必备的文件读写指南
2021/06/23 Python
用PYTHON去计算88键钢琴的琴键频率和音高
2022/04/10 Python
数据设计之权限的实现
2022/08/05 MySQL
postgresql中如何执行sql文件
2023/05/08 PostgreSQL