PHP Класс yii\captcha\CaptchaAction

CaptchaAction is used together with Captcha and CaptchaValidator to provide the CAPTCHA feature. By configuring the properties of CaptchaAction, you may customize the appearance of the generated CAPTCHA images, such as the font color, the background color, etc. Note that CaptchaAction requires either GD2 extension or ImageMagick PHP extension. Using CAPTCHA involves the following steps: 1. Override [[\yii\web\Controller::actions()]] and register an action of class CaptchaAction with ID 'captcha' 2. In the form model, declare an attribute to store user-entered verification code, and declare the attribute to be validated by the 'captcha' validator. 3. In the controller view, insert a Captcha widget in the form.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Action
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$backColor the background color. For example, 0x55FF00. Defaults to 0xFFFFFF, meaning white color.
$fixedVerifyCode the fixed verification code. When this property is set, CaptchaAction::getVerifyCode will always return the value of this property. This is mainly used in automated tests where we want to be able to reproduce the same verification code each time we run the tests. If not set, it means the verification code will be randomly generated.
$fontFile the TrueType font file. This can be either a file path or path alias.
$foreColor the font color. For example, 0x55FF00. Defaults to 0x2040A0 (blue color).
$height the height of the generated CAPTCHA image. Defaults to 50.
$imageLibrary the rendering library to use. Currently supported only 'gd' and 'imagick'. If not set, library will be determined automatically.
$maxLength the maximum length for randomly generated word. Defaults to 7.
$minLength the minimum length for randomly generated word. Defaults to 6.
$offset the offset between characters. Defaults to -2. You can adjust this property in order to decrease or increase the readability of the captcha.
$padding padding around the text. Defaults to 2.
$testLimit how many times should the same CAPTCHA be displayed. Defaults to 3. A value less than or equal to 0 means the test is unlimited (available since version 1.1.2).
$transparent whether to use transparent background. Defaults to false.
$width the width of the generated CAPTCHA image. Defaults to 120.

Открытые методы

Метод Описание
generateValidationHash ( string $code ) : string Generates a hash code that can be used for client-side validation.
getVerifyCode ( boolean $regenerate = false ) : string Gets the verification code.
init ( ) Initializes the action.
run ( ) Runs the action.
validate ( string $input, boolean $caseSensitive ) : boolean Validates the input to see if it matches the generated code.

Защищенные методы

Метод Описание
generateVerifyCode ( ) : string Generates a new verification code.
getSessionKey ( ) : string Returns the session variable name used to store verification code.
renderImage ( string $code ) : string Renders the CAPTCHA image.
renderImageByGD ( string $code ) : string Renders the CAPTCHA image based on the code using GD library.
renderImageByImagick ( string $code ) : string Renders the CAPTCHA image based on the code using ImageMagick library.
setHttpHeaders ( ) Sets the HTTP headers needed by image response.

Описание методов

generateValidationHash() публичный метод

Generates a hash code that can be used for client-side validation.
public generateValidationHash ( string $code ) : string
$code string the CAPTCHA code
Результат string a hash code generated from the CAPTCHA code

generateVerifyCode() защищенный метод

Generates a new verification code.
protected generateVerifyCode ( ) : string
Результат string the generated verification code

getSessionKey() защищенный метод

Returns the session variable name used to store verification code.
protected getSessionKey ( ) : string
Результат string the session variable name

getVerifyCode() публичный метод

Gets the verification code.
public getVerifyCode ( boolean $regenerate = false ) : string
$regenerate boolean whether the verification code should be regenerated.
Результат string the verification code.

init() публичный метод

Initializes the action.
public init ( )

renderImage() защищенный метод

Renders the CAPTCHA image.
protected renderImage ( string $code ) : string
$code string the verification code
Результат string image contents

renderImageByGD() защищенный метод

Renders the CAPTCHA image based on the code using GD library.
protected renderImageByGD ( string $code ) : string
$code string the verification code
Результат string image contents in PNG format.

renderImageByImagick() защищенный метод

Renders the CAPTCHA image based on the code using ImageMagick library.
protected renderImageByImagick ( string $code ) : string
$code string the verification code
Результат string image contents in PNG format.

run() публичный метод

Runs the action.
public run ( )

setHttpHeaders() защищенный метод

Sets the HTTP headers needed by image response.
protected setHttpHeaders ( )

validate() публичный метод

Validates the input to see if it matches the generated code.
public validate ( string $input, boolean $caseSensitive ) : boolean
$input string user input
$caseSensitive boolean whether the comparison should be case-sensitive
Результат boolean whether the input is valid

Описание свойств

$backColor публичное свойство

the background color. For example, 0x55FF00. Defaults to 0xFFFFFF, meaning white color.
public $backColor

$fixedVerifyCode публичное свойство

the fixed verification code. When this property is set, CaptchaAction::getVerifyCode will always return the value of this property. This is mainly used in automated tests where we want to be able to reproduce the same verification code each time we run the tests. If not set, it means the verification code will be randomly generated.
public $fixedVerifyCode

$fontFile публичное свойство

the TrueType font file. This can be either a file path or path alias.
public $fontFile

$foreColor публичное свойство

the font color. For example, 0x55FF00. Defaults to 0x2040A0 (blue color).
public $foreColor

$height публичное свойство

the height of the generated CAPTCHA image. Defaults to 50.
public $height

$imageLibrary публичное свойство

the rendering library to use. Currently supported only 'gd' and 'imagick'. If not set, library will be determined automatically.
С версии: 2.0.7
public $imageLibrary

$maxLength публичное свойство

the maximum length for randomly generated word. Defaults to 7.
public $maxLength

$minLength публичное свойство

the minimum length for randomly generated word. Defaults to 6.
public $minLength

$offset публичное свойство

the offset between characters. Defaults to -2. You can adjust this property in order to decrease or increase the readability of the captcha.
public $offset

$padding публичное свойство

padding around the text. Defaults to 2.
public $padding

$testLimit публичное свойство

how many times should the same CAPTCHA be displayed. Defaults to 3. A value less than or equal to 0 means the test is unlimited (available since version 1.1.2).
public $testLimit

$transparent публичное свойство

whether to use transparent background. Defaults to false.
public $transparent

$width публичное свойство

the width of the generated CAPTCHA image. Defaults to 120.
public $width