Captcha 'get A New Code' Does Not Work

Hi all,

Instead of generating a fresh ‘captcha’ code when I click on ‘Get a new Code’ I get the below output:


I am at a loss. I have gone through the forums but have drawn a blank. Has anyone else had this problem.

Output from Firebug:


Screen shot 2013-03-20 at 1.40.gif

I am using Yii 1.1.13

My set up is below.

The instructions for setting up a Yii app seems pretty clear…

On the server the ‘framework’ files are in the the ‘private’ folder which is not accessible online.

This is the file structure:



… index.php






However when I set up the folders and files with the above instructions, the web application did not work.

Currently all folders and sub folders permissions are ‘rxwr-wr-w’.

Below are my code for for the website.

This is the code in my /test/protected/yiic.php file:


// change the following paths if necessary




This is my ‘/test/index.php’ file contents.


// change the following paths if necessary





NB: All other Yii functionality works such as ‘crumbs’ and form error checking and sending emails.

The ‘.htaccess’ file in the same directory as the above ‘index.php’ file.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

SetEnv APPLICATION_ENV development













  public $name;

	public $email;

	public $phone;

	public $subject;


	public $verifyCode;


	 * Declares the validation rules.


	public function rules()


		return array(

			// name, email, subject and body are required

			array('name, email, phone', 'required'),

			// email has to be a valid email address

			array('email', 'email'),

			// verifyCode needs to be entered correctly

			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),




class SiteController extends Controller



	public function actions()


		return array(

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





			// page action renders "static" pages stored under 'protected/views/site/pages'

			// They can be accessed via: index.php?r=site/page&view=FileName







	 * I have added a contact us form on the index page, which is a modified version of the standard ContactForm.



	public function actionIndex()


		$model=new ContactForm;








				$headers="From: $name <{$model->email}>\r\n".

					"Reply-To: {$model->email}\r\n".

					"MIME-Version: 1.0\r\n".

					"Content-type: text/plain; charset=UTF-8";


				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');








	* @return array action filters 


	public function filters() 


		return array( 'accessControl', // perform access control for CRUD operations 



/** * Specifies the access control rules. 

* This method is used by the 'accessControl' filter. 

* @return array access control rules 


public function accessRules()


return array(


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





Finally: /views/site/index.php

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

	<div class="row">

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


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

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


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

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

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


	<?php endif; ?>

I hope that this is comprehensive enough. Any help would be appreciated.

Thanks in advance.

Furthermore, what happens when I click on ‘Get a new code’ is that instead of just refreshing the captcha image it takes me to an entirely new page and just shows the output that the link creates.

When I hit the back button on the browser the captcha image has new characters.

The generated ‘url’ in the browser after clicking ‘Get a new Code’ is:


According to what I have read on the forums is that in the above ‘url’ “\/test” refers to the folder that the “index.php” file resides ie /test/ where the web app is launched.

And that "\/site" refers to the SiteController.

And “\/captcha” is an ‘action’ in the SiteController.

Why then is the whole page refreshed? Only the captcha image should be altered, leaving the rendered web page as is.

I have tried several things by commenting out portions of code in the CCaptcha.php file and also the CCaptchaAction.php files but to no avail.

What else can I do to rectify this problem?


I have uploaded a sample Yii app on the host server and the issue does not occur. So I can rule out server side issues.

I’ve noticed that if I disable ‘//layouts/’ and just render the basic web page, the “Get a New Code” works.

I have a question regarding the way ‘layouts’ work in Yii. I have read the following information “Understanding the view rendering flow”, but in my quest to solve my problem I am more confused by the setup on Yii.

In ‘/protected/components/Controller.php’ I have commented out

public $layout='//layouts/column1';

and have removed the file ‘column1.php’ from the ‘/layout’ folder to ensure that it has no affect. But when I surf to the site, the page still renders as it should. Therefore, it seems that Yii is set up to look for a file called ‘main.php’ as a last resort?

If this is the case, why then all the fuss with the above setup?

I have used this extension , this is working fine for me, Try this one.


Thanks for your suggestion regarding using the captcha extension: it looks good, but I am still having the same problems with the link "Get a new code".

I finally found the problem:

This javascript file somehow affected the captcha code thus causing my problem.

<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery-1.2.6.min.js"></script>  

Even though I had commented out this code previously I had not noticed a change.