2

How do I create a CAPTCHA response/challenge in an application running on Zend Framework? Are there any built in libraries for this?

Dale Athanasias
  • 471
  • 3
  • 16
Ajay Sahu
  • 29
  • 1
  • 2

2 Answers2

2

Checkout the direct link from Zend Framework - http://framework.zend.com/manual/en/zend.captcha.introduction.html

Generate:

//generates an instance of Zend_Captcha
//returns ID of captcha session
function generateCaptcha() {
    $captcha = new Zend_Captcha_Image();

    $captcha->setTimeout(’300′)
    ->setWordLen(’6′)
    ->setHeight(’80′)
    ->setFont(‘/path/to/your/fontFile.ttf’)
    ->setImgDir(‘/path/to/your/image/captchaDirectory’);

    $captcha->generate();    //command to generate session + create image

    return $captcha->getId();   //returns the ID given to session & image
}   //end function generateCaptcha

Validate:

//validates captcha response
function validateCaptcha($captcha) {
    $captchaId = $captcha[‘id’];
    $captchaInput = $captcha[‘input’];

    $captchaSession = new Zend_Session_Namespace(‘Zend_Form_Captcha_’ . $captchaId);
    $captchaIterator = $captchaSession->getIterator();
    $captchaWord = $captchaIterator[‘word’];

    if( $catchaWord ) {
        if( $captchaInput != $captchaWord ){
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }

}

Examples:

http://mnshankar.wordpress.com/2009/08/13/understanding-zend-captcha-zend_captcha_image/

http://krmaurya.com/13/hello-world/

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66
0

Possible answers can be derived from the following stackoverflow.com questions:

Community
  • 1
  • 1
sdolgy
  • 6,963
  • 3
  • 41
  • 61