/* 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. tyvj1089 smrtfun

    背景 广东汕头聿怀初中 Train#2 Problem3 描述  现有N个物品,第i个物品有两个属性A_i和B_i.在其中选取若干个物品,使得sum{A_i + B_i}最大,同时sum{A_i},s ...

  2. ZOJ 3696 Alien's Organ

    泊松分布.... Alien's Organ Time Limit: 2 Seconds      Memory Limit: 65536 KB There's an alien whose name ...

  3. jquery.validate.js插件使用

    jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...

  4. AssetBundle loading failed because.....已解决

    http://blog.csdn.net/ldghd/article/details/9632455 *****************************      一      ******* ...

  5. embed标签loop=true背景音乐无法循环

    在html网页中加入背景音乐并设置为循环播放.一开始用<embed>标签,设置loop="true", 但是结果发现在IE浏览器可以,但是在chrome浏览器却无法实现 ...

  6. CentOS下SNMP的安装与使用

    CentOS下SNMP的安装与使用   导读 简单网络管理协议(SNMP),由一组网络管理的标准组成,包含一个应用层协议(application layer protocol).数据库模型(datab ...

  7. oracle插入数据时解决和旧数据id的冲突

    我们在使用oracle创建一个主键的时候需要让他自增, 但是他跟mysql不同,需要创建序列,具体看下面: 可以删除之前创建的sequence,我们在重新创建一个: DROP SEQUENCE SJG ...

  8. android studio--百度定位集成001

    安卓现在的大趋势已经是普遍使用androidstudio(安装包[https://yunpan.cn/ckc54idj3JVJb  访问密码 664f])了.这个是集成的一个好的环境. 今天来搞个百度 ...

  9. C# Mvc中文件下载

    public ActionResult DownloadFile(string id) { var fileinfo = CommonAnnexService.Get(id); if (fileinf ...

  10. 2017 苹果强制https

    苹果的ATS(App Transport Security)对服务器硬性3点要求: ① ATS要求TLS1.2或者更高,TLS 是 SSL 新的别称. ② 通讯中的加密套件配置要求支持列出的正向保密. ...