<分区>
如何在 Zend Framework 上运行的应用程序中创建 CAPTCHA 响应/质询?是否有任何内置库?
<分区>
如何在 Zend Framework 上运行的应用程序中创建 CAPTCHA 响应/质询?是否有任何内置库?
最佳答案
检查来自 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/
关于javascript - 如何在 zend 框架中创建验证码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6464657/