输入banner图图片脚本导航/分类

yii2中验证码图片不显示

yii的项目开发过程中,经常使用到验证码,yii框架提供了CCaptchaAction类,来提供验证码图片功能,经常会碰到验证码图片不显示的问题。

主要有两个问题导致:

1、bom问题(把文件涉及到bom的php代码去掉bom即可)。

2、 输出图像之前,没有加ob_clean()清空输出缓冲区。

//加此代码块解决
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);

相关文章教程推荐:yii教程

以上就是yii2中验证码图片不显示的详细内容,更多请关注Gxlcms其它相关文章!