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新手上路(十一)
Oct 09 PHP
PHP网站基础优化方法小结
Sep 29 PHP
php csv操作类代码
Dec 14 PHP
浅析PHP程序防止ddos,dns,集群服务器攻击的解决办法
Jun 18 PHP
神盾加密解密教程(三)PHP 神盾解密工具
Jun 08 PHP
Smarty变量调节器失效的解决办法
Aug 20 PHP
PHP会话处理的10个函数
Aug 11 PHP
php将一维数组转换为每3个连续值组成的二维数组
May 06 PHP
PHP发送AT指令实例代码
May 26 PHP
PHP 极验验证码实例讲解
Sep 29 PHP
PHP设计模式之原型模式定义与用法详解
Apr 03 PHP
php中钩子(hook)的原理与简单应用demo示例
Sep 03 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
模拟OICQ的实现思路和核心程序(三)
2006/10/09 PHP
php实现12306火车票余票查询和价格查询(12306火车票查询)
2014/01/14 PHP
Eclipse的PHP插件PHPEclipse安装和使用
2014/07/20 PHP
php判断文件夹是否存在不存在则创建
2015/04/09 PHP
PHP页面转UTF-8中文编码乱码的解决办法
2015/10/20 PHP
PHP对象克隆clone用法示例
2016/09/28 PHP
php中各种定义变量的方法小结
2017/10/18 PHP
查找Oracle高消耗语句的方法
2014/03/22 Javascript
JavaScript中双叹号!!作用示例介绍
2014/09/21 Javascript
详解nodejs微信公众号开发——5.素材管理接口
2017/04/11 NodeJs
jQuery基于cookie实现换肤功能实例
2017/10/14 jQuery
JS实现字符串去重及数组去重的方法示例
2018/04/21 Javascript
angularjs手动识别字符串中的换行符方法
2018/10/02 Javascript
JS实现计算小于非负数n的素数的数量算法示例
2019/02/26 Javascript
JavaScript实现简单验证码
2020/08/24 Javascript
Vue实现鼠标经过文字显示悬浮框效果的示例代码
2020/10/14 Javascript
记录一次websocket封装的过程
2020/11/23 Javascript
[03:17]DOTA2英雄基础教程 剧毒术士
2013/12/12 DOTA
[09:37]2018DOTA2国际邀请赛寻真——不懈追梦的Team Serenity
2018/08/13 DOTA
python让图片按照exif信息里的创建时间进行排序的方法
2015/03/16 Python
Python中的自省(反射)详解
2015/06/02 Python
浅谈flask截获所有访问及before/after_request修饰器
2018/01/18 Python
python贪婪匹配以及多行匹配的实例讲解
2018/04/19 Python
ActiveMQ:使用Python访问ActiveMQ的方法
2019/01/30 Python
Django框架 查询Extra功能实现解析
2019/09/04 Python
Python 将json序列化后的字符串转换成字典(推荐)
2020/01/06 Python
CSS3 animation实现逐帧动画效果
2016/06/02 HTML / CSS
阿里巴巴美国:Alibaba美国
2019/11/24 全球购物
爷爷追悼会答谢词
2014/01/24 职场文书
平面设计求职信
2014/03/10 职场文书
我们的节日中秋节活动总结
2015/03/23 职场文书
机关干部正风肃纪心得体会
2016/01/15 职场文书
2016会计专业自荐信范文
2016/01/28 职场文书
详解Laravel服务容器的优势
2021/05/29 PHP
java中重写父类方法加不加@Override详解
2021/06/21 Java/Android
python开发飞机大战游戏
2021/07/15 Python