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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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