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

The verification code image is not displayed in yii2

王林
王林Original
2019-12-17 16:45:512900browse

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);

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!

Statement:
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