Yii Framework Forum: can't see Captcha image - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

can't see Captcha image Rate Topic: -----

#1 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 14 May 2010 - 08:44 PM

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? :/

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


0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 15 May 2010 - 03:15 AM

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

#3 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 15 May 2010 - 08:26 AM

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

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 May 2010 - 08:58 AM

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/ma...nstallation.php
0

#5 User is offline   echo66 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-May 10

Posted 15 May 2010 - 09:59 AM

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

#6 User is offline   resplendent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 60
  • Joined: 22-May 09
  • Location:Singapore

Posted 16 May 2010 - 10:08 PM

depending what php version and operating system you using:

for windows:
  • locate your php.ini at C:\php\php.ini
  • uncomment this line extension=php_gd2.dll
  • restart your apache server


for linux:
  • is even simpler, install php-gd2 package
  • restart your apache server

0

#7 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 29-March 10

Posted 23 July 2010 - 04:24 AM

Hello every body !

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

Posted Image


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 ?
0

#8 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 23 July 2010 - 06:19 AM

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

#9 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 29-March 10

Posted 23 July 2010 - 02:05 PM

I have an error :

Quote

Error 404
Unable to resolve the request "index.php?r=UserController/captcha".



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

#10 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 23 July 2010 - 02:12 PM

should be:
index.php?r=user/captcha
Don't say what you think, think what you say
The problem is communication! Excess of communication!
1

#11 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 29-March 10

Posted 23 July 2010 - 02:21 PM

it's work !!

But i have an other error :

Quote

Error 403
You are not authorized to perform this action.


I am not authorized to see it !
0

#12 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 23 July 2010 - 03:24 PM

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

#13 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 29-March 10

Posted 23 July 2010 - 03:37 PM

it's work,

Thanks for your help !
0

#14 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 28 July 2010 - 02:32 PM

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?
0

#15 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 29-March 10

Posted 28 July 2010 - 02:51 PM

if you speek french :

http://morgan-blog.o...i-54373756.html
0

#16 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 28 July 2010 - 03:00 PM

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...to+comments.htm The problem is that I have exactly followed this instructions and it is not working...
0

#17 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 29 July 2010 - 03:09 AM

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?
0

#18 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 29 July 2010 - 03:15 AM

Make sure the charset is UTF-8 without BOM.
1

#19 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 29 July 2010 - 03:31 AM

Perfect! Thanks a lot :)
0

#20 User is offline   zama janan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-July 10
  • Location:Canada

Posted 01 August 2010 - 04:52 PM

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.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users