gpt4 book ai didi

php - Zend_Form_Element_Captcha 异常问题...?

转载 作者:可可西里 更新时间:2023-11-01 01:06:44 25 4
gpt4 key购买 nike

在我的 Zend 应用程序中,我遇到了 Captcha 元素的异常问题。当我尝试查看我在本地计算机上使用此 Captcha 元素的表单时,它工作正常,但是当我将它上传到我的 Debian 服务器时,它无法正常工作...!!!

区别如下: enter image description here

正如您在本地主机上看到的,验证码内的文本显示给用户,而在服务器 [Debian] 上,文本丢失了!!!!!!

我使用以下代码在我的 Zend 表单上创建了验证码元素:

    $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));
}

谁能告诉我我在做什么错误......?

提前致谢......

最佳答案

  1. 将此字体更改为任何其他字体以检查 Debian 是否支持它
  2. 设置字体和图片的绝对路径:

    $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
    ),
    );
  3. 您使用哪个 ZF 版本?因为在 1.7 之后装饰器中有一个错误,你必须设置自己的装饰器否则 Zend_Captcha 不起作用:

    $captcha = new Zend_Form_Element_Captcha('Captcha', $captchaOptions);
    $captchaDecor = array_merge(array(new Decorator_Captcha()), $captcha->getDecorators());
    $captcha->setDecorators($captchaDecor);

Decorator_Captcha 文件如下

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 异常问题...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9140266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com