Home > PHP Framework > YII > How to generate verification code in yii2

How to generate verification code in yii2

爱喝马黛茶的安东尼
Release: 2019-12-09 13:05:32
Original
3026 people have browsed it

How to generate verification code in yii2

1. Add the code in the controller

public function actionCaptcha(){
    $c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
    $c->getVerifyCode(true);
    return $c->run();
}
Copy after login

2. Call the verification code through the following method

$c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
$code = $c->getVerifyCode();
Copy after login

$code is generated before Verification code

Note: $this represents the current controller, this method is only suitable for use in one controller.

3. Front-end call:

Write a

PHP Chinese website has a large number of free Yii introductory tutorials, everyone is welcome to learn!

The above is the detailed content of How to generate verification code in yii2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template