Reputation: 1430
i m using secureimage solution to generate captcha code
i have this error on chrom console
Resource interpreted as Image but transferred with MIME type text/html
and when entring on this url directly used as image src
securimage_show.php?sid=fa5e1eb19c3a534885632e
i have this error
Failed to generate captcha image, content has already been output. This is most likely due to misconfiguration or a PHP error was sent to the browse
someone have idea ?
Note: it works for me in localhost wampserver but not on remote server
Edit:
the code from the captcha opensource code generating php errors :
protected function output()
{
if ($this->canSendHeaders() || $this->send_headers == false) {
if ($this->send_headers) {
// only send the content-type headers if no headers have been output
// this will ease debugging on misconfigured servers where warnings
// may have been output which break the image and prevent easily viewing
// source to see the error.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
switch ($this->image_type) {
case self::SI_IMAGE_JPEG:
if ($this->send_headers) header("Content-Type: image/jpeg");
imagejpeg($this->im, null, 90);
break;
case self::SI_IMAGE_GIF:
if ($this->send_headers) header("Content-Type: image/gif");
imagegif($this->im);
break;
default:
if ($this->send_headers) header("Content-Type: image/png");
imagepng($this->im);
break;
}
} else {
echo '<hr /><strong>'
.'Failed to generate captcha image, content has already been '
.'output.<br />This is most likely due to misconfiguration or '
.'a PHP error was sent to the browser.</strong>';
}
imagedestroy($this->im);
restore_error_handler();
if (!$this->no_exit) exit;
}
Upvotes: 0
Views: 3543
Reputation: 107
Quick Fix:
Just replace canSendHeaders function in securimage.php file
From
protected function canSendHeaders() {
if (headers_sent()) {
// output has been flushed and headers have already been sent
return false;
} else if (strlen((string) ob_get_contents()) > 0) {
// headers haven't been sent, but there is data in the buffer that will break image and audio data
return false;
}
return true;
}
To
protected function canSendHeaders() {
ob_get_clean();
if (headers_sent()) {
// output has been flushed and headers have already been sent
return false;
} else if (strlen((string) ob_get_contents()) > 0) {
// headers haven't been sent, but there is data in the buffer that will break image and audio data
return false;
}
return true;
}
Upvotes: 4
Reputation: 1
had the same problem this morning with a development that i've done some month ago, while deploying today i've forgotten that i place an echo on the top of securimage.php, hope this can help
Upvotes: 0
Reputation: 109
Failed to generate captcha image, content has already been output. This is most likely due to misconfiguration or a PHP error was sent to the browse
I think you are missing reference to the dll in your web.config
Upvotes: 0
Reputation: 91734
Judging by this statement that evaluates to false
:
if ($this->canSendHeaders() || $this->send_headers == false) {
you have already sent stuff to the browser before you call the output
function.
In order to be able to use that function, you must make sure that nothing has been sent to the browser; no empty lines or spaces before opening <?php
tags, no echo
statements, etc.
Upvotes: 0