Home > PHP Framework > YII > The verification code image is not displayed in yii2

The verification code image is not displayed in yii2

王林
Release: 2019-12-17 16:45:51
Original
2949 people have browsed it

The verification code image is not displayed in yii2

During the project development process of yii, verification codes are often used. The yii framework provides the CCaptchaAction class to provide the verification code image function. We often encounter the problem that the verification code image is not displayed. .

There are two main problems:

1. BOM problem (just remove the BOM from the PHP code that involves the BOM).

2. Before outputting the image, ob_clean() is not added to clear the output buffer.

//加此代码块解决
if(function_exists('ob_clean')){
@ob_clean();
}
imagecolordeallocate($image,$foreColor);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
Copy after login

Recommended related articles and tutorials: yii tutorial

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

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