PHP code example of long399 / yii2-math-captcha

1. Go to this page and download the library: Download long399/yii2-math-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

long399 / yii2-math-captcha example snippets


public function actions()
{
    return [
        ...
        'captcha' => [
            'class' => \long399\captcha\MathCaptchaAction::class,
            'fixedVerifyCode' => YII_ENV_TEST ? '399' : null,
            'minLength' => 0,
            'maxLength' => 1000,
        ],
        ...
    ];
}

class MyModel extends \yii\db\ActiveRecord
{
    public $captcha;
    ...
    public function rules()
    {
        return [
            ...
            ['captcha', 'captcha', 'captchaAction' => '/site/captcha'],
            ...
        ];
    }
    ...
}

...
echo $form->field($model, 'captcha')->widget(\yii\captcha\Captcha::class, [
    'captchaAction' => "/site/captcha",
    'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]);
...

public function actions()
{
    return [
        ...
        'captcha' => [
            'class' => \app\components\actions\MathCaptchaAction::class,
            'fixedVerifyCode' => YII_ENV_TEST ? '399' : null,
            'minLength' => 0,
            'maxLength' => 1000,
            'operations' => ['-'],
        ],
        ...
    ];
}

public function actions()
{
    return [
        ...
        'captcha' => [
            'class' => \app\components\actions\MathCaptchaAction::class,
            'fixedVerifyCode' => YII_ENV_TEST ? '399' : null,
            'minLength' => 0,
            'maxLength' => 1000,
            'operations' => ['+', '-', '*'],
        ],
        ...
    ];
}