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中验证码图片不显现的细致内容,更多请关注ki4网别的相干文章!