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中支持多种编码的中文字符串截取函数!
Mar 20 PHP
关于PHP5 Session生命周期介绍
Mar 02 PHP
PHP实现的汉字拼音转换和公历农历转换类及使用示例
Jul 01 PHP
php字符串函数学习之substr()
Mar 27 PHP
php程序内部post数据的方法
Mar 31 PHP
WordPress迁移时一些常见问题的解决方法整理
Nov 24 PHP
使用PHP如何实现高效安全的ftp服务器(一)
Dec 20 PHP
PHP+iframe图片上传实现即时刷新效果
Nov 18 PHP
php批量删除操作(数据访问)
May 23 PHP
Yii2.0框架实现带分页的多条件搜索功能示例
Feb 20 PHP
PHP架构及原理知识点详解
Dec 22 PHP
phpstudy隐藏index.php的方法
Sep 21 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中iconv函数转码时截断字符问题的解决方法
2015/01/21 PHP
WordPress中注册菜单与调用菜单的方法详解
2015/12/18 PHP
PHP利用Mysql锁解决高并发的方法
2018/09/04 PHP
jQuery html() in Firefox (uses .innerHTML) ignores DOM changes
2010/03/05 Javascript
js输入框邮箱自动提示功能代码实现
2013/12/10 Javascript
js判断上传文件类型判断FileUpload文件类型代码
2014/05/20 Javascript
javascript 兼容各个浏览器的事件
2015/02/04 Javascript
js实现的简单radio背景颜色选择器代码
2015/08/18 Javascript
JS实现滑动菜单效果代码(包括Tab,选项卡,横向等效果)
2015/09/24 Javascript
深入浅析JS是按值传递还是按引用传递(推荐)
2016/09/18 Javascript
js数组去重的hash方法
2016/12/22 Javascript
微信小程序实现基于三元运算验证手机号/姓名功能示例
2019/01/19 Javascript
vue elementui 实现搜索栏公共组件封装的实例代码
2020/01/20 Javascript
[01:18:33]Secret vs VGJ.S Supermajor小组赛C组 BO3 第一场 6.3
2018/06/04 DOTA
[02:28]PWL开团时刻DAY3——Ink Ice与DeMonsTer之间的勾心斗角
2020/11/03 DOTA
python笔记(2)
2012/10/24 Python
Python使用scrapy抓取网站sitemap信息的方法
2015/04/08 Python
Python中的super用法详解
2015/05/28 Python
Python实现将目录中TXT合并成一个大TXT文件的方法
2015/07/15 Python
django 解决manage.py migrate无效的问题
2018/05/27 Python
Python根据文件名批量转移图片的方法
2018/10/21 Python
python爬取酷狗音乐排行榜
2019/02/20 Python
pycharm 批量修改变量名称的方法
2019/08/01 Python
python Web flask 视图内容和模板实现代码
2019/08/23 Python
Python通过两个dataframe用for循环求笛卡尔积
2020/04/29 Python
OpenCV 之按位运算举例解析
2020/06/19 Python
利用CSS的Sass预处理器(框架)来制作居中效果
2016/03/10 HTML / CSS
html5-websocket基于远程方法调用的数据交互实现
2012/12/04 HTML / CSS
美国迪克体育用品商店:DICK’S Sporting Goods
2018/07/24 全球购物
入学申请自荐信范文
2014/02/26 职场文书
婚假请假条格式及范文
2014/04/10 职场文书
片区教研活动总结
2014/07/02 职场文书
四风批评与自我批评发言稿
2014/10/14 职场文书
员工担保书范本
2015/09/22 职场文书
2019年怎样写好导游词?
2019/07/02 职场文书
导游词之河北野三坡
2019/12/11 职场文书