2017 © Pedro Peláez
 

library captcha

captcha package

image

barrett/captcha

captcha package

  • Thursday, November 9, 2017
  • by Barrett-M82A1
  • Repository
  • 2 Watchers
  • 7 Stars
  • 79 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 41 Forks
  • 0 Open issues
  • 13 Versions
  • 5 % Grown

The README.md

Barrett-captcha

验证码扩展库, (*1)

使用

一、安装

composer require barrett/captcha, (*2)

二、初始化配置

引入本扩展库后,在实例化时可以传递配置参数,用于处理不同的场景。, (*3)

$Captcha = new barrett\Captcha(['setZh'=>true,'length'=>4]);

配置表如下, (*4)

参数名 参数类型 默认值 说明
key string Barrett 验证码加密key
destroy Boolean true 验证成功后是否销毁
expire integer 1800 验证码过期时间(s)
length integer 5 验证码长度
setZh Boolean false 使用中文验证码
width integer 180 图片验证码默认宽度
height integer 50 图片验证码默认高度
fontSize integer 20 验证码字体大小(px)
fontTtf string 验证码字体,不设置随机获取
useImgBg Boolean false 使用背景图片
useCurve Boolean true 是否画混淆曲线
useNoise Boolean true 是否添加杂点
bg array [243, 251, 254] 背景颜色

二、创建验证码

本扩展目前支持:图形验证码、数字验证码(短信用)两种,使用方法如下:, (*5)

创建图形验证码, (*6)

$Captcha = new barrett\Captcha();
return $Captcha->createImg('user');

创建短信验证码, (*7)

$Captcha = new barrett\Captcha();
//createNum方法会返回被创建的验证码
$code = $Captcha->createNum('user');
//使用短信发送数字验证码
$Sms->sendToPhone($code['data]);

验证码效验, (*8)

$Captcha = new barrett\Captcha();
return $Captcha->check($_POST,'user');

如输出结果异常请检查页面头部信息是否正常!如:Content-type:image/png 是否设置

三、场景标识

用例:客户更改已绑定的手机号,需要在同一个页面生成两个验证码(原手机验证码、新手机验证码)。 1.原手机创建验证码加入唯一场景标识:, (*9)

$old = $Captcha->createNum('old');

2.新手机创建验证码同样加入唯一场景标识:, (*10)

$new = $Captcha->createNum('new');

3.当用户提交数据时则根据唯一场景标识来检测对应场景的验证码是否正确,而不会出现相同页面多次调用后不能效验的问题。, (*11)

The Versions

09/11 2017

dev-master

9999999-dev

captcha package

  Sources   Download

Apache-2.0

by Avatar Barrett-M82A1

09/11 2017

2.2

2.2.0.0

captcha package

  Sources   Download

Apache-2.0

by Avatar Barrett-M82A1

11/10 2017

2.1

2.1.0.0

captcha package

  Sources   Download

Apache-2.0

by Avatar Barrett-M82A1

15/09 2017

2.0.x-dev

2.0.9999999.9999999-dev

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

15/09 2017

2.0

2.0.0.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

06/07 2016

v1.0.7

1.0.7.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

30/06 2016

v1.0.6

1.0.6.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

12/06 2016

v1.0.5

1.0.5.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

03/06 2016

v1.0.4

1.0.4.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

12/05 2016

v1.0.3

1.0.3.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

11/05 2016

v1.0.2

1.0.2.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

11/05 2016

v1.0.1

1.0.1.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin

11/05 2016

v1.0.0

1.0.0.0

captcha package for thinkphp5

  Sources   Download

Apache-2.0

by Avatar yunwuxin