我正在codeigniter 2.4中工作。我必須在我的項目中使用google recaptcha。以下是我的代碼。如何在codeigniter中集成google reCAPTCHA?
// field validation
$this->form_validation->set_rules('recaptcha_challenge_field', 'Captcha Code', 'trim|required|xss_clean|callback_checkCaptcha');
回調函數是:
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;
}
}
但我收到此錯誤:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/offer.php
Line Number: 59
請幫我在哪裏,我錯了。
謝謝。
您已經爲驗證碼的類?哪一行是59? –
我已將該庫包含在構造函數中作爲 $ this-> load-> library('recaptcha'); – user2826169
第59行是 if($ resp-> is_valid) – user2826169