I beleive I had similar problem. On testing machine everything was fine, but on production machine problem occured. Yii code was correct, but GD library did not calculate correct coordinates for next captcha letter. I overrided function for captcha image generation.
I’ve seen the same thing too. I haven’t had a chance to debug it deeply, however, I have noticed that the problem goes away in my case if I disable AJAX validation, i.e., set enableAjaxValidation to false for the CActiveForm that the captcha resides within, i.e.,
Just to emphasize, those who can afford not to use AJAX validation on the page where you put the captcha, simply avoid AJAX validation for the issue not to happen. I just did so and solved my issue.
Actually, I think this is not 100% correct approach to re-generate captcha on every ajax validation (which Yii does and what leads to continuous misunderstanding among developers). This is why I extended standard CCaptchaValidator to the following simple one.
class AjaxCaptchaValidator extends CCaptchaValidator
{
/**
* Skips captcha validation/regeneration during ajax requests
*/
public $skipAjaxValidation = true;
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object,$attribute)
{
if($this->skipAjaxValidation
&& Yii::app()->request->isAjaxRequest) return;
parent::validateAttribute($object,$attribute);
}
}
Place it in extensions/validators/AjaxCaptchaValidator.php and use like this:
$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);
}
If still not working :
/* simulate a click on "refresh captcha" for GET requests */
if (!Yii::app()->request->isPostRequest)
Yii::app()->clientScript->registerScript(
'initCaptcha',
'$(".captcha a").trigger("click");',
CClientScript::POS_READY
);
i just solved the same problem in tracuba.com/es/registro.html … the thing is I modified my config file main.php with notepad from windows, then i upload the file and then the problem appears…
For solving it i download the previous version of main.php and modified again but using notepad++ and uploaded the file again…don’t now why…maybe was a codification problem…who knows??