yii2-captcha
yii2-captcha copied to clipboard
Headers already sent
After added in actions
'captcha' => [
'class' => 'juliardi\captcha\CaptchaAction',
]
an error appears on page site/captcha
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /var/www/html/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php on line 561. in /var/www/html/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/vendor/yiisoft/yii2/web/ErrorHandler.php(135): yii\web\Response->send()
#2 /var/www/html/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in /var/www/html/vendor/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php on line 561. in /var/www/html/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response->send()
#2 /var/www/html/frontend/web/index.php(18): yii\base\Application->run()
#3 {main}
I think it should be like this:
//in CaptcahAction@run
return $this->captchaBuilder->get(); // instead of $this->captchaBuilder->output();
It works.
And i think $this->captchaBuilder->get()
and $this->captchaBuilder->output()
generated jpg.
CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90
Hello @kratkar , sorry for the late response. While I can't reproduce the error you found, I think your suggestion is good and I tried to follow it. This library now uses
return $this->captchaBuilder->get($quality);
instead of
$this->captchaBuilder->output();
It also support the quality
parameter to set the generated image quality. You can find the usage in README.md.
The Content-Type
header also changed from image/png
to image/jpeg
.
I hope this can solve the error you found.