Captcha image issue.

I am following the blog tutorial but am stuck at adding the captcha image into the add comment form.

The image source is not of an image but the local path of  src="/index.php?r=post/captcha".

How is this happening? Can I not run this from my local machine?

in that particular uri, php changes the headers to image/jpeg… so that the browser knows to render it like an image. check this link:


it may not render on your computer because you need the php extension gd2. are you using wamp on windows or are you in a linux environment?

Thanks for the reply.

I don’t quite understand. The URI index.php?r=post/captcha should display the captcha image? If that was the case then I would think that the URL http://www.yiiframew…?r=post/captcha would also show a captcha image.

I am running Linux and gd2 and php5-gd are both installed. I have tried this on two computers now running the same set-up.


have you any errors when you go to page e.g. http://localhost/myw…?r=post/captcha ?

It gives me the login screen. If I'm logged in it returns a Unauthorized error which tells me I need to change the accessRules.

I have fixed this error by adding 'captcha' to the actions array in AccessRules() in PostController.

Thank you.


in your post controller (PostController.php) you have to allow captcha action for all users or authenticated. For all users you can do

I hope that this help you :)