小编Ste*_*ano的帖子

Zend框架和ReCaptcha

我需要在我的ZF应用程序中的表单中插入ReCaptcha.我正在尝试遵循官方文档,但ReCaptcha服务总是返回错误'wrong-captcha-sol'.我正在使用的代码:

(在表格中)

// configure the captcha service
$privateKey = 'XXXXXXXXXXXXXXXXXXX';
$publicKey = 'YYYYYYYYYYYYYYYYYYYY';
$recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey);

// create the captcha control
$captcha = new Zend_Form_Element_Captcha('captcha',
                                array('captcha' => 'ReCaptcha',
                                      'captchaOptions' => array(
                                          'captcha' => 'ReCaptcha',
                                          'service' => $recaptcha)));

$this->addElement($captcha);
Run Code Online (Sandbox Code Playgroud)

(在控制器中)

$recaptcha = new Zend_Service_ReCaptcha('YYYYYYYYYYYYY', 'XXXXXXXXXXXXXXX');

$result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'),
                             $this->_getParam('recaptcha_response_field'));

if (!$result->isValid()) {
    //ReCaptcha validation error
}
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

zend-framework recaptcha

7
推荐指数
2
解决办法
8359
查看次数

标签 统计

recaptcha ×1

zend-framework ×1