Forcing Login With Yii-User Captcha Dosen't Show.

Hello All,

I am using the yii user extention and I was using a modified version of this tutorial from Larry Ullman Forcing Login.

Everything works great, it forces users to the login whenever a user tries to go to any URL except the login, registration, and recover password.

The problem I am having is it isn’t showing the Captcha on the registration screen. It shows the refresh Captcha but not the actual image. I think i have the url wrong but I really have no clue. I know it is something with this because it shows when I disable it.

Thank you in advance!

in protected/modules/user/usermodule.php

I added:

public $captcharefreshUrl = array("/user/registration/captcha/refresh/1");

public $captchaUrl = array("/user/registration/captcha");

.../captcha/refresh/1 is the url to the "Get New Code" link

in protected/components/requirelogin.php (I created this)

I have:


class RequireLogin extends CBehavior


    public function attach($owner)


            $owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));



    public function handleBeginRequest($event)


            $app = Yii::app();

            $user = $app->user;

            $recovery = trim(is_array(Yii::app()->getModule('user')->recoveryUrl) ? Yii::app()->getModule('user')->recoveryUrl[0] : Yii::app()->getModule('user')->recoveryUrl, '/');

            $registration = trim(is_array(Yii::app()->getModule('user')->registrationUrl) ? Yii::app()->getModule('user')->registrationUrl[0] : Yii::app()->getModule('user')->registrationUrl, '/');

            $captcha = trim(is_array(Yii::app()->getModule('user')->$captchaUrl) ? Yii::app()->getModule('user')->captchaUrl[0] : Yii::app()->getModule('user')->captchaURL, '/');

            $captcharefreshUrl = trim(is_array(Yii::app()->getModule('user')->captcharefreshUrl) ? Yii::app()->getModule('user')->captcharefreshUrl[0] : Yii::app()->getModule('user')->captcharefreshUrl, '/');           

            $request = trim($app->urlManager->parseUrl($app->request), '/');

            $login = trim($user->loginUrl[0], '/');

            $login = trim(is_array($user->loginUrl) ? $user->loginUrl[0] : $user->loginUrl, '/');

            // Restrict guests to public pages.

            $allowed = array($login,$recovery,$registration, $captcha, $captcharefreshUrl);

            if ($user->isGuest && !in_array($request, $allowed))



            // Prevent logged in users from viewing the login page.

            $request = substr($request, 0, strlen($login));

            if (!$user->isGuest && $request == $login)


            $url = $app->createUrl($app->homeUrl[0]);