2011-06-24 3 views

答えて

3

チェックアウトZend Frameworkのからの直接リンク - http://framework.zend.com/manual/en/zend.captcha.introduction.html

は生成します

//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 

検証:

//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; 
    } 

} 

例:

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

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

関連する問題