captcha image is not displayed on hosted site

Hi all,

I am confused with captcha feature : Images are displayed on my localhost, but aren’t on my hosted site.

I found many ideas on this forum :

  • check that Duality.ttf file is transferred with binary mode

  • check actions in controller

  • check accessRules in controller

  • check the yii requirements on the server

  • change ‘allowEmpty’=>CCaptcha::checkRequirements()) with ‘allowEmpty’=>!extension_loaded(‘gd’)

  • check GD on the server

But issue still occurses.

On my PC (Win7, wamp), it works fine, based on the yum extension, without any modification in this feature. PhpInfo returns these informations about GD :

GD Support : enabled

GD Version : bundled (2.0.34 compatible)

FreeType Support : enabled

FreeType Linkage : with freetype

FreeType Version : 2.4.3

GIF Read Support : enabled

GIF Create Support : enabled

JPEG Support : enabled

libJPEG Version : 6b

PNG Support : enabled

libPNG Version : 1.2.44

WBMP Support : enabled

XBM Support : enabled

Directive ; Local Value ; Master Value ;

gd.jpeg_ignore_warning ; 0 ; 0 ;

On my hosted site (Linux, Apache 2.0), /testdrive, /framework and /requirements directories are transferred. PhpInfo returns these informations about GD :

GD Support : enabled

GD Version : 2.0 or higher

FreeType Support : enabled

FreeType Linkage : with freetype

FreeType Version : 2.3.11

T1Lib Support : enabled

GIF Read Support : enabled

GIF Create Support : enabled

JPG Support : enabled

PNG Support : enabled

WBMP Support : enabled

Can somebody help me understand this behavior ?

Thanks.

are you using friendly urls on both places

Yes, same url management.

There is an issue in the header of the png : an invalid "0A" character first.

A relevant PNG file (on my localhost) starts with :

89 50 4E 47 0D 0A 1A 0A ==> \211 P N G \r \n \032 \n

The generated PNG on my hosted site starts with :

0A 89 50 4E 47 0D 0A 1A 0A ==> \n \211 P N G \r \n \032 \n

Some sites say that such an extra character comes from a bad include php file. I dont find it.

Thanks for your thoughts.

can you paste the code of your captcha

Please find the pieces of codes.

Thanks.

The form (part of) :




	<?php if(CCaptcha::checkRequirements()): ?>

	<div class="row">

		<?php echo $form->labelEx($model,'verifyCode'); ?>

		<div>

		<?php $this->widget('CCaptcha'); ?>

		<?php echo $form->textField($model,'verifyCode'); ?>

		</div>




CCaptchaAction.php is standard from yii-framework-web-widgets-captcha with no modification




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




CCaptcha.php is standard from yii-framework-web-widgets-captcha with no modification

Found a solution.

Dont know exactly why I have the problem on an hosted site, and why it’s ok on my localhost.

Because there is an extra unexpected character, i cleaned the output buffer just before writing the header.

CCaptchaAction.php :




		ob_clean(); // added

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



Works fine.

Thank Goood and thank you!

Hi where is this put the code ?

God! I encountered the very same issue on my host site and this SOLVED THE PROBLEM!!!!!

Symptom: GET request fired okay, no response header, strange character (in IE it displays as a ‘?’) before PNG file header.