Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

CAPTCHA image cannot be displayed because it contains errors

Avatar of Tocacar
TocacarFlag for United States of America asked on
Web Languages and StandardsPHP
45 Comments1 Solution6368 ViewsLast Modified:
I am working my way through a tutorial book ((Practical Web 2.0 Applications with PHP) and cannot get the CAPTCHA image to appear. The page returns as a "captcha (PNG Image)" that states:

      "The image "...URL here..." cannot be displayed, because it contains errors."

I have GD2 installed and enabled.  The code to generate the captcha is attached (the font path in $opt is retrieved from a settings.ini file and is:

paths.data  = "C:/Sites/phpweb20/data"

In that directory (data) there is a TrueType font file called VeraBd.

Can anyone see what I'm doing wrong? Any help/ advice would be most appreciated.
    class UtilityController extends CustomControllerAction
        public function captchaAction()
            $session = new Zend_Session_Namespace('captcha');

            // check for existing phrase in session
            $phrase = null;
            if (isset($session->phrase) && strlen($session->phrase) > 0)
                $phrase = $session->phrase;

            $captcha = Text_CAPTCHA::factory('Image');

            $opts = array('font_size' => 20,
                          'font_path' => Zend_Registry::get('config')->paths->data,
                          'font_file' => 'VeraBd.ttf');
            $captcha->init(120, 60, $phrase, $opts);

            // write the phrase to session
            $session->phrase = $captcha->getPhrase();

            // disable auto-rendering since we're outputting an image

            header('Content-type: image/png');
            echo $captcha->getCAPTCHAAsPng();
Avatar of Slick812
Slick812Flag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 45 Comments.
See Answers