/* 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. Container View 使用小技巧

    一.传值,顺传 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { TVC *vc = segue.destin ...

  2. MyBatis学习总结(一)——MyBatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  3. iframe框架在IE浏览器,360兼容浏览器下将白色背景设为透明色

    <IFRAME ID="Frame1" SRC="transparentBody.htm"></IFRAME> iframe在大部分浏览 ...

  4. Bash 的 no-fork 优化

    我们知道,Bash 在执行一个外部命令时,会先 fork() 一个子进程,然后在子进程里面执行 execve() 去加载那个外部程序.fork 子进程是会耗性能的,所以 Bash 会在下面几种情况下不 ...

  5. [Search Engine] 搜索引擎技术之网络爬虫

    随着互联网的大力发展,互联网称为信息的主要载体,而如何在互联网中搜集信息是互联网领域面临的一大挑战.网络爬虫技术是什么?其实网络爬虫技术就是指的网络数据的抓取,因为在网络中抓取数据是具有关联性的抓取, ...

  6. PHP文件包含漏洞攻防实战(allow_url_fopen、open_basedir)

    摘要 PHP是一种非常流行的Web开发语言,互联网上的许多Web应用都是利用PHP开发的.而在利用PHP开发的Web应用中,PHP文件包含漏洞是一种常见的漏洞.利用PHP文件包含漏洞入侵网站也是主流的 ...

  7. SpringMVC上传文件的三种方式

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

  8. mongo-c-driver使用VS2013编译

    1.下载mongo-c-driver源码文件 使用github来下载. git clone https://github.com/mongodb/mongo-c-driver.git 下载完之后,进入 ...

  9. Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  10. 【目录】Leetcode

    Leetcode 1.动态规划 Palindrome Partitioning II(hard) ☆ Distinct Subsequences(hard) Edit Distance (hard) ...