can't see Captcha image

Hi again!

I’m having a problem since i installed yii framework in my machine.

I can’t see the captcha generated images, even in the “Contact.php” example. :mellow:

seems the extension gd isn’t loaded because the ‘if’ condition in the view evaluates as false…

so, what is happening? :confused:




class RegisterUserForm extends CFormModel{

	

	/**

	 * Reordenar os atributos para serem lidos no controlador

	 * Verificar se a password ´e igual ´a confirmaçao

	 * Verificar se o email ´e valido

	 * Verificar se a data de nascimento est´a no formato correcto

	 */

	

	public $isInternal;

	public $identifier; //username

	public $internalID; //CLIP

	public $name;

	public $email;

	public $sex;

	public $password;

	public $confirmPassword;

	public $photo;

	public $location;

	public $birthday;

	public $verifyCode;

	

	

	public function rules(){

		

		return array(

		

			array('email','required'),

			

			array('email','email'),

			

			//array('sex','in','range'=>array('masculino','feminino')),

			

			//array('password', 'compare', 'compareAttribute'=>'confirmPassword'),

			

			//array('identifier','clipIDValidate'),

			

			//array('emails','email'),

			

			//array('photo','url'),

			

			//array('birthday','myCheckDate'),

			

			//array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd'))

		

		);

	}

}






<?php


class UserController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to 'column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='column2';


	/**

	 * @var CActiveRecord the currently loaded data model instance.

	 */

	private $_model;


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}

	

	public function actions()

	{

		return array(

			// captcha action renders the CAPTCHA image displayed on the contact page

			'captcha'=>array(

                'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

			),

			

		);

	}


        public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view','captcha'),

				'users'=>array('*'),

			),

			array('allow',

				'actions'=>array('activateUser','registerUser'),

				'users'=>array('?'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


}







<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'user-form',

	'enableAjaxValidation'=>false,

)); ?>

<?php echo $form->errorSummary($model); ?>


	<div class="row">

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

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

		<?php echo $form->error($model,'photo'); ?>

	</div>


	<div class="row">

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

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

		<?php echo $form->error($model,'identifier'); ?>

	</div>

	

	<div class="row">

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

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

		<?php echo $form->error($model,'email'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'Identificador do CLIP (opcional)'); ?>

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

		<?php echo $form->error($model,'internalID'); ?>

	</div>

	

	<div class="row">

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

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

		<?php echo $form->error($model,'name'); ?>

	</div>

	

	<div class="row">

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

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

		<?php echo $form->error($model,'password'); ?>

	</div>


	<div class="row">

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

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

		<?php echo $form->error($model,'confirmPassword'); ?>

	</div>

	

	<div class="row">

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

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

		<?php echo $form->error($model,'sex'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx($model,'Localização'); ?>

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

		<?php echo $form->error($model,'location'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx($model,'Data de nascimento'); ?>

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

		<?php echo $form->error($model,'birthday'); ?>

	</div>

	

	<?php if(extension_loaded('gd')): ?>

	<div class="row">

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

		<div>

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

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

		</div>

		<div class="hint">Please enter the letters as they are shown in the image above.

		<br/>Letters are not case-sensitive.</div>

	</div>

	<?php endif; ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Registar'); ?>

	</div>

<?php $this->endWidget(); ?>




As you said: the gd extension is not loaded. Make sure your webserver loads that extension and your problems are gone.

sorry for this question but…how do i load that extension? I’m a noob at Yii and any framework… ;D

That’s not a Yii issue, but a question how to enable this extension in your PHP installation. Check your php.ini and read here for details (ignore the compilation stuff):

http://de.php.net/manual/en/image.installation.php

How do i know what is the directory that GD was installed?

depending what php version and operating system you using:

for windows:

[list=1]

[*]locate your php.ini at C:\php\php.ini

[*]uncomment this line extension=php_gd2.dll

[*]restart your apache server

[/list]

for linux:

[list=1]

[*]is even simpler, install php-gd2 package

[*]restart your apache server

[/list]

Hello every body !

I have the same problem, but my GD extension is installed correctly :

my user models :


 <?php

class user extends CActiveRecord

{

	public $verifyCode;

[...]


public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),

[...]


public function attributeLabels()

	{

		return array(

			'verifyCode'=>'Code de verification',


[...]

?>

my UserController :


<?php


[...]

public function actions()

			{

					return array(

							'captcha'=>array(

									'class'=>'CCaptchaAction',

									'backColor'=>0xEBF4FB,

							),

					);

			}

[...]


?>



and my _form




	<?php if(extension_loaded('gd')): ?>

	<div class="row">

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

		<div>

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

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

		</div>

		<div class="hint">Veuillez retapez les lettres que vous voyer sur l'image.

		<br/>Les caractères ne sont pas sensible à la case.</div>

	</div>

	<?php endif; ?>



Where is problem ?

What happens if you call the captcha action directly? Like with index.php?r=<yourcontrollername>/captcha

I have an error :

But in my controllers dir i have a file who is name is "UserController.php"

should be:

index.php?r=user/captcha

it’s work !!

But i have an other error :

I am not authorized to see it !

Yes, you have to allow all users to see it in your accessRules() method.

it’s work,

Thanks for your help !

I also have a problem with captcha. I see the input field and "reload captcha" link, but I do not see the image itself. When I look into HTML source of generated page, <img> tag is there, but it has a problem with rendering image.

I have tried everything you advice here, Guys, and it still does not work… So:

  • I do have GD module loaded. There is a condition

 if (extension_loaded('gd'))

before showing any part of this.

  • I do have an action defined in controller and I do have permissions for it.

  • When I try to open index.php?r=<yourcontrollername>/captcha I do not see 403 but an image broken while rendering. (Chrome shows a missing image icon. Firefox shows information: "image can not be displayed, because it contains errors".) So it is not a permission issue.

And now the strangest part: I have captcha used in the other part of the site (yii-user extension) and… it works perfectly. Of course everything: view, controller are pretty much the same.

I really have no idea what is going wrong. Any guesses?

if you speek french :

Thanks. I do not speak French, unfortunately, but as far as I understood this is more or less what is described here: http://saptarshi.org/post/6/Yii%3A+Adding+captcha+to+comments.htm The problem is that I have exactly followed this instructions and it is not working…

OK, I know what is the reason. It is the charset issue.

I have to use URF-8 in my application. When I change the coding of a file to UTF-8 captcha is not working. When I change it back to ANSI – it is ok again.

Any ideas how to solve it?

Make sure the charset is UTF-8 without BOM.

Perfect! Thanks a lot :)

Hi guys,

I do have a same problem and did follow all above step by step codes and still having same problem.

I also have this …blogdemo-enhanced application installed and it shows image on that form and I did compare word by word in all …Model…Controller…Views but still image doesn’t show up on my another application Comment Form.

But there is one thing on my blog application Contact form the image shows up but on Comment Form doesn’t.

I spend the whole day to find it out but finally give up…:)

Any other reason where I’m missing some thing.

An early reply will be appreciated.