/* note:
* this 指向当前对象本身
* self 指向当前类
* parent 指向父类
*/ /* 验证码工具类
* @author pandancode
* @date 20150-12-1
*/
class Verification_Code{ private $_vode;
private $_vode_len;
private $_img_handle;
private $_img_width;
private $_img_height;
private $_img_type;
private $_img_bg_color;
private $_img_color; /* 单实例 */
private static $_instance; /* 获取当前实例 */
public static function getInstance(){
if( !(self::$_instance instanceof self) ){
self::$_instance = new self;
}
return self::$_instance;
} /* 构造函数,设置 为private,禁止外部访问 */
private function __Construct(){} /* 设置 为private,禁止外部访问,禁止外部访问 */
private function __clone(){} /* 生成验证码图片前设置参数
* @param string vode 验证码
* @param int vode_len 验证码长度
* @param string img_type 生成图片格式,默认为png
*/
public function set_param($vode,$vode_len,$width,$height,$img_type='png',$img_bg_color=array('R'=>250,'G'=>'250','B'=>'250'),$img_color=array('R'=>0,'G'=>0,'B'=>0)){
$this->_vode = $vode;
$this->_vode_len = $vode_len;
$this->_img_width = $width;
$this->_img_height = $height;
$this->_img_type = $_img_type;
$this->_img_bg_color = $img_bg_color;
$this->_img_color = $img_color;
} /* 生成图片
*/
public function create_img(){
$this->_img_handle = ImageCreate($this->_img_width,$this->_img_height);
$this->_img_bg_color = ImageColorAllocate($this->_img_handle,$this->_img_bg_color['R'],$this->_img_bg_color['G'],$this->_img_bg_color['B']);
$this->_img_color = ImageColorAllocate($this->_img_handle,$this->_img_color['R'],$this->_img_color['G'],$this->_img_color['B']); //填充背景颜色
Imagefill($this->_img_handle,0,0,$this->_img_bg_color);
ImageString($this->_img_handle,10,10,10,$this->_vode,$this->_img_color); ob_clean();
header('Content-type:image/png');
Imagepng($this->_img_handle);
} } $img_tool = Verification_Code::getInstance();
$img_tool->set_param('ABVS',4,80,40);
$img_tool->create_img();

  

PHP生成验证码及单实例应用的更多相关文章

  1. JAVA WEB项目中生成验证码及验证实例(附源码及目录结构)

    [我是一个初学者,自己总结和网上搜索资料,代码是自己敲了一遍,亲测有效,现将所有的目录结构和代码贴出来分享给像我一样的初学者] 作用 验证码为全自动区分计算机和人类的图灵测试的缩写,是一种区分用户是计 ...

  2. C#生成验证码实例

    常用生成验证码实例封装: /// <summary> /// 生成内存位图 /// </summary> /// <param name="Code" ...

  3. spring mvc 使用kaptcha配置生成验证码实例

    SpringMVC整合kaptcha(验证码功能) 一.依赖 <dependency> <groupId>com.github.penggle</groupId> ...

  4. python-随机生成验证码实例

    需求:随机生成验证码, 思路: 1.生成一个随机数,65-90 2.数字转化为字母:chr(数字) #!/usr/bin/env python # -*- coding:utf-8 -*- impor ...

  5. Django(十六)基于模板的登录案例:登录装饰器、csrf攻击方式及防护、ajax的Post 的csrf开启写法、生成验证码、加验证码登录、反向解析+传参

    一.csrf攻击 1.1 csrf攻击(跨站请求伪造) [csrf攻击即]:通过第3方网站,伪造请求(前提条件是你已经登录正常网站,并保存了session或cookie登录信息且没有退出),第三方网站 ...

  6. laravel 生成验证码的方法

    在Laravel中有很多图片验证码的库可以使用,本篇介绍其中之一:gregwar/captcha,这个库比较简单,在Laravel中比较常用.下面我们就来介绍下使用细节: 首先, composer.j ...

  7. java web学习总结(九) -------------------通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:

  8. PHP 动态生成验证码

    ……机器人会在网站中搜寻允许他们插入广告的输入表单,在虚拟世界没有什么能阻挡它们胡作非为.这些机器人效率极高,完全不关心所攻击的表单的本来用途.它们唯一的目标就是用它们的垃圾广告覆盖你的内容,残忍地为 ...

  9. 关于struts和Spring 结合到一起之后存在ACtion创建单实例还是多

    struts 2的Action是多实例的并非单例,也就是每次请求产生一个Action的对象.原因是:struts 2的Action中包含数据,例如你在页面填写的数据就会包含在Action的成员变量里面 ...

随机推荐

  1. [Maven] 变态问题收集

    1.新换的系统,eclipse运行起来之后,一直报错Missing artifact 折腾了好久,没法了,把服务器上的仓库直接压缩,传到本地计算机上,覆盖本地仓库,完美解决这个问题! 2.tomcat ...

  2. System.Properties和System.getenv区别

    网上很多使用的是getProperties.说获得系统变量,但是其实不正确.getProperties中所谓的"system properties"其实是指"java s ...

  3. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  4. 一段freemarker高级分页效果的代码

    <a onclick="page(1)">首页</a> [#if currpage != 1] [#assign last=currpage - 1] &l ...

  5. Linux进程间通信(七):消息队列 msgget()、msgsend()、msgrcv()、msgctl()

    下面来说说如何用不用消息队列来进行进程间的通信,消息队列与命名管道有很多相似之处.有关命名管道的更多内容可以参阅我的另一篇文章:Linux进程间通信 -- 使用命名管道 一.什么是消息队列 消息队列提 ...

  6. spark streaming 接收 kafka 数据java代码WordCount示例

    http://www.cnblogs.com/gaopeng527/p/4959633.html

  7. 文本框value联动修改

    <input id="ipt-edit" value="" /><input id="ipt-target" value= ...

  8. 示例开发过程记录:meteor,react,apollo

    本示例记录一个开发过程: 1)参考 Meteor React TUTORIAL教程 https://www.meteor.com/tutorials/react/creating-an-app 2). ...

  9. 为什么operator>>(istream&, string&)能够安全地读入长度未知的字符串?

    一般而言,实现"读入用户输入的字符串",程序中自然不能对用户输入的长度有所限定.这在C++中很容易实现,而在C中确没那么容易. 这一疑问,我在刚学C++的时候也在脑中闪现过:不过很 ...

  10. 使用原生ajax处理json组成的数组

    和前一篇文章一样,直接上代码了,只是做个记录. 数据的提供页面,tigong.php <?php header("content-type:text/html;charset=utf- ...