PHPackages                             klintlili/yii2-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. klintlili/yii2-captcha

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

klintlili/yii2-captcha
======================

Captcha library wrapper for Yii2

01PHP

Since Nov 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/klintlili/yii2-captcha)[ Packagist](https://packagist.org/packages/klintlili/yii2-captcha)[ RSS](/packages/klintlili-yii2-captcha/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 Captcha Extension
======================

[](#yii2-captcha-extension)

[Gregwar's Captcha library](https://github.com/Gregwar/Captcha) wrapper for Yii2.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Either run

```
php composer.phar require --prefer-dist klintlili/yii2-captcha "*"

```

or add

```
"klintlili/yii2-captcha": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

This extension has 3 different steps. First is calling `CaptchaAction` to generate CAPTCHA image, then rendering CAPTCHA image in view, and validating user input against the generated CAPTCHA code. Here is how to setup this extension for each step :

##### Action

[](#action)

Add the following method into your Controller.

```
public function actions()
{
    return [
        'captcha' => [
            'class' => 'klintlili\captcha\CaptchaAction',
            //'length' => 5, // captcha character count
            //'width' => 150, // width of generated captcha image
            //'height' => 40, // height of generated captcha image
        ],
    ];
}
```

Some configurable attributes are :

- `length`An integer value to set the generated CAPTCHA character count
- `width`An integer value to set the width of generated CAPTCHA image
- `height`An integer value to set the height of generated CAPTCHA image

##### View file

[](#view-file)

Add the following code to your view to render CAPTCHA image and input.

```
use klintlili\captcha\Captcha;
...

```

You can also use ActiveForm instance to render CAPTCHA input.

```
use klintlili\captcha\Captcha;
...
