大佬教程收集整理的这篇文章主要介绍了PHP-Zend_Form_Element_Captcha的异常问题?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的Zend应用程序中,我遇到了Captcha元素的异常问题.当我尝试查看在本地计算机上使用此Captcha元素的表单时,它工作正常,但是当我将其上载到Debian Server时,它工作不正常… !!!
区别如下:
正如您在localhost上看到的那样,验证码中的文本将显示给用户,而在Server [Debian]上,该文本丢失了!
我曾使用followig代码在Zend表单上创建Captcha元素:
@H_197_11@ $elements = array();
$captchaElement = new Zend_Form_Element_Captcha('captcha',
array('label' => "Ihr generierter Textcode:",
'captcha' => array('captcha' => 'Image',
'name' => 'myCaptcha',
'wordLen' => 5,
'timeout' => 300,
'font' => 'verdana.ttf',
'imgDir' => 'captcha/',
'imgurl' => '/captcha/')
)
);
$elements[] = $captchaElement;
foreach ($elements as $index => $element)
{
$element->setAttrib('tabindex', ($index + 1));
}
谁能告诉我我在做什么错…?
提前致谢…..
解决方法:
>将此字体更改为其他字体,以检查Debian是否支持它
>设置字体和图像的绝对路径:
@H_197_11@$captchaOptions = array(
'label' => "Enter key",
'captcha' => array(
'captcha' => 'Image',
'wordLen' => 4,
'width' => 197,
'timeout' => 120,
'expiration'=> 300,
'font' => APPLICATION_PATH . '/../public/ttf/arial.ttf',
'imgDir' => APPLICATION_PATH . '/../public/images/captcha',
'imgurl' => '/images/captcha/',
'gcFreq' => 5
),
);
>您使用什么ZF版本?在1.7之后,由于装饰器中存在一个错误,您必须设置自己的装饰器,否则Zend_Captcha无法正常工作:
@H_197_11@$captcha = new Zend_Form_Element_Captcha('Captcha', $captchaOptions);
$captchaDecor = array_merge(array(new Decorator_Captcha()), $captcha->getDecorators());
$captcha->setDecorators($captchaDecor);
下面的Decorator_Captcha文件
@H_197_11@class Decorator_Captcha extends Zend_Form_Decorator_Abstract
{
/**
* Render captcha
*
* @param String $content
* @return String
*/
public function render($content)
{
$element = $this->getElement();
if (!method_exists($element, 'getCaptcha')) {
return $content;
}
$view = $element->getView();
if (null === $view) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$captcha = $element->getCaptcha();
$markup = $captcha->render($view, $element);
switch ($placement) {
case 'PREPEND':
$content = $content . $separator . $markup;
break;
case 'APPEND':
default:
$content = $markup . $separator . $content;
}
return $content;
}
}
以上是大佬教程为你收集整理的PHP-Zend_Form_Element_Captcha的异常问题?全部内容,希望文章能够帮你解决PHP-Zend_Form_Element_Captcha的异常问题?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。