Captcha Not Updating The Image After Page Refresh

Hi, i am implementing captcha in my signup page.

The problem is it is displaying same image after page refreshes.

Here is my code.

Model.php





class Users extends CActiveRecord

{

	public $verifyCode; 


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

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

		// will receive user inputs.

		return array(

			

			// verifyCode needs to be entered correctly

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

			

		);

	}




Controller.php








class UsersController extends karmora

{


    public function accessRules()

    {

        return array(

            array('allow', 

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

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

            	),

        );

    } 




    public function actions()

    {

        return array(

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

            'captcha'=>array(

                'class'=>'CCaptchaAction',

                'backColor'=>0xFFFFFF,

            ),

        );

    } 




View.php




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

			'id'=>'users-signup-form',

			'enableAjaxValidation'=>false,

              		'enableClientValidation'=>true,

              		'clientOptions'=>array(

              			'validateOnSubmit'=>true,

              		),

)); ?>


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

	    <div class="hint">Please enter the letters as shown.

	         <br/>Letters are not case-sensitive.

            </div>

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

	</div>

<?php endif; ?>




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




please guide me what is wrong with this code. it works fine if i get new code by clicking "Get new code" link.

pass a unique_id on capatcha


<?php 

$unique_id=rand(0,99999);

?>


 <?php $this->widget('CCaptcha', array('buttonOptions' => array('style' => 'display:none', 'id' => $unique_id),'id'=>'image_captcha')); ?>

[size=2]Thanks for your reply but it didn’t change anything except “Get new code” is hidden.[/size]

In your view page just put the code


<?php

                $session = Yii::app()->session;

                $prefixLen = strlen(CCaptchaAction::SESSION_VAR_PREFIX);

                foreach ($session->keys as $key) {

                    if (strncmp(CCaptchaAction::SESSION_VAR_PREFIX, $key, $prefixLen) == 0)

                        $session->remove($key);

                }

?>

[size=2]Thanks the issue is resolved. [/size]:)