Yii captcha doesn't work

I found captcha doesn’t work with my application without any error and then i checked the blog example’s contact page with captcha in the Yii file, also doesn’t work.

I then completely rewrote the captchaAction and it doesn’t work either.

I’m sure my GD library works fine.

Can anybody help me out? What may be the problem?

Two things come to mind that you might want to check. First, did you overrie the actions() method in your controller class? You’ll need to add the following:


class YourController extends Controller

{

    public function actions()

    {

        return array(

            'captcha' => array(

                'class' => 'CCaptchaAction',

                'backColor' => 0xFFFFFF,

            ),

        );

    }

}

If you did that and it still doesn’t work, check your controller access. When you are overwritten accessRules(), you need to make the captcha action available for everyone, like this:


class YourController extends Controller

{

    public function accessRules() {

        return array('allow', 'actions' => array('captcha'), 'users' => array('*'));

    }

}

Hope that helps.

Thanks for your remind jodev :) . I think I forgot to add access rules. But I solved this in a much more complicated way. I want to customize my captcha and I found captcha,both mine and Yii’s, cannot be rendered inside the framework anyway (Maybe because of the access rules you remind me). So I have to put it outside the framework in the root file, problem is, in this way, it cannot share sessions with Yii, so i can’t pass the captcha result to validate. I use cache to solve it. Well… whatever, I’ve solved it though in an inefficient way. And i don’t want to entangle on this issue anymore. I’ve wasted 3 days on this. Really tired about it ;).

Thank you again. I’ll try your solution if i want to use Yii’s captcha someday.

Thank you!!! This worked for me. I just needed to add the captcha into the allowed actions.