如何在codeigniter中集成谷歌reCAPTCHA?

use*_*169 5 codeigniter

我在codeigniter 2.4工作.我必须在我的项目中使用谷歌recaptcha.Below是我的代码.

// field validation
$this->form_validation->set_rules('recaptcha_challenge_field', 'Captcha Code', 'trim|required|xss_clean|callback_checkCaptcha');
Run Code Online (Sandbox Code Playgroud)

回调功能是:

    function checkCaptcha($captcha){
    $resp = $this->recaptcha->recaptcha_check_answer ( $this->input->ip_address(), $this->input->post('recaptcha_challenge_field',true), $this->input->post('recaptcha_response_field',true));

    if($resp->is_valid)
    {
        return true;
        }

    else 
    {
         $this->form_validation->set_message('checkCaptcha', 'Sorry Invalid captcha code');
         return false;
        }

    }
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

  A PHP Error was encountered

  Severity: Notice

  Message: Trying to get property of non-object

 Filename: controllers/offer.php

 Line Number: 59
Run Code Online (Sandbox Code Playgroud)

我帮我错了.

谢谢.

use*_*169 2

我已经更新了我的代码,现在它对我有用。在验证码库中,我已公开 is_valid 属性,然后替换

if($resp->is_valid)
Run Code Online (Sandbox Code Playgroud)

if($this->recaptcha->is_valid)
Run Code Online (Sandbox Code Playgroud)

现在它对我有用。

感谢所有回答我问题的人。