承接 bugcat/captcha 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bugcat/captcha

Composer 安装命令:

composer require bugcat/captcha

包简介

PHP captcha with Chinese

README 文档

README

Installation

The Captcha Service Provider can be installed via Composer by requiring the bugcat/captcha package and setting the minimum-stability to dev in your project's composer.json.

{
    "require": {
        "bugcat/captcha": "~0.1"
    },
    "minimum-stability": "dev"
}

or

Require this package with composer:

composer require bugcat/captcha

Update your packages with composer update or install with composer install.

In Windows, you'll need to include the GD2 DLL php_gd2.dll in php.ini. And you also need include php_fileinfo.dll and php_mbstring.dll to fit the requirements of bugcat/captcha's dependencies.

Usage

To use the Captcha Service Provider, you need to store the captcha characters and verify the correctness of the user's input. This captcha package is only responsible for generating characters and drawing captcha pictures.

Use it first.

    use Bugcat\Captcha\Captcha;

Load it then.

    $captcha = new Captcha();

Generate a new captcha using custom configuration, get the captcha codes, store it.

    $config = []; //custom configuration
    $codes = $captcha->gnrt($config);
    $_SESSION['captcha'] = $codes;

Output the image to the user

    $captcha->img();

Last, verify user input

    if ( $_POST['captcha'] == $_SESSION['captcha'] ) {
        //do something.
    } else {
        //do something.
    }

Configuration

There is a simple example for configuration in the captcha package, you can see it like this.

    $captcha = new Captcha();
    var_dump($captcha::CFG_EXP);

This is the full description.

    $config = [
        //Whether need a border, 1 is need and 0 is not, default 1.
        'border'   => '1|0', 
        
        //The verification code length, 1 at least, default 4.
        'charnum'  => '4', 
        
        //The fontsize of captcha,  using px, 8 at least, default 16.
        'fontsize' => '16',
        
        //The code direction, 0 is horizontal and  1 is vertical, default 0.
        'codedir'  => '1|0',
        
        //The font of code, use existing list or custom, default simhei.
        //This package provides these fonts: simhei, ABeeZee_regular, Asap_700, Khand_500, Open_Sans_regular, Roboto_regular, Ubuntu_regular, ygyxsziti2.0 .
        //If use custom, it needs the full and usable path.
        'font'     => 'simhei|Roboto_regular|/var/www/html/test/fonts/custom.ttf',
        
        //The character pool for captcha, use existing list or custom, default CHS.
        //This package provides these characters: 
        //  CHS : Chinese Simplified
        //  CHT : Chinese Traditional
        //  ENG : 2346789ABCDEFGHJMNPQRTUXYZ
        'text'     => 'CHS|CHT|ENG|custom string allow spaces because it will be ignored',
    ];

Example Usage

use Bugcat\Captcha\Captcha;

class Auth
{
    private $captcha;

    public function __construct()
    {
        $this->captcha = new Captcha();
    }

    public function vcode()
    {
        $config = ['charnum' => 2, 'text' => 'CHT'];
        $codes = $this->captcha->gnrt($config);
        $_SESSION['captcha'] = $codes;
        
        $this->captcha->img();
    }
    
    public function register()
    {
        if ( $_POST['CSRF'] ) {
            if ( !$this->verify() ) {
                die( 'the verification code is error.' );
            }
            //do something.
        }
        //do something.
    }
    
    private function verify()
    {
        if ( empty($_POST['captcha']) || empty($_SESSION['captcha']) ) {
            return false;
        }
        if ( $_POST['captcha'] == $_SESSION['captcha'] ) {
            return true;
        } else {
            retrun false;
        }
    }
    
}

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固