reCaptcha 集成:模型还是函数?
reCaptcha Integration: Model or function?
我正在使用本教程将 reCaptcha 与我的项目集成。但是在我无法完全理解并写在下面的第四步我该怎么办?
Add the following function to your MY_Validation class as seen below in the libraries folder. (If you don’t already have one a MY_Validation class, make one.)
教程第四步下类似这样的代码。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Validation 扩展 CI_Validation
{
function MY_Validation()
{
parent::CI_Validation();
}
function recaptcha_matches()
{
$CI =& get_instance();
$CI->config->load('recaptcha');
$public_key = $CI->config->item('recaptcha_public_key');
$private_key = $CI->config->item('recaptcha_private_key');
$response_field = $CI->input->post('recaptcha_response_field');
$challenge_field = $CI->input->post('recaptcha_challenge_field');
$response = recaptcha_check_answer($private_key,
$_SERVER['REMOTE_ADDR'],
$challenge_field,
$response_field);
if ($response->is_valid)
{
return TRUE;
}
else
{
$CI->validation->recaptcha_error = $response->error;
$CI->validation->set_message('recaptcha_matches', 'The %s is incorrect. Please try again.');
return FALSE;
}
}
}
你能帮我解决这个问题吗?下面是教程link
有很多简单的库可以用于重新验证
下载这个https://github.com/appleboy/CodeIgniter-reCAPTCHA
(顺便说一句,您的教程 link 不起作用)
我正在使用本教程将 reCaptcha 与我的项目集成。但是在我无法完全理解并写在下面的第四步我该怎么办?
Add the following function to your MY_Validation class as seen below in the libraries folder. (If you don’t already have one a MY_Validation class, make one.)
教程第四步下类似这样的代码。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Validation 扩展 CI_Validation {
function MY_Validation()
{
parent::CI_Validation();
}
function recaptcha_matches()
{
$CI =& get_instance();
$CI->config->load('recaptcha');
$public_key = $CI->config->item('recaptcha_public_key');
$private_key = $CI->config->item('recaptcha_private_key');
$response_field = $CI->input->post('recaptcha_response_field');
$challenge_field = $CI->input->post('recaptcha_challenge_field');
$response = recaptcha_check_answer($private_key,
$_SERVER['REMOTE_ADDR'],
$challenge_field,
$response_field);
if ($response->is_valid)
{
return TRUE;
}
else
{
$CI->validation->recaptcha_error = $response->error;
$CI->validation->set_message('recaptcha_matches', 'The %s is incorrect. Please try again.');
return FALSE;
}
}
}
你能帮我解决这个问题吗?下面是教程link
有很多简单的库可以用于重新验证
下载这个https://github.com/appleboy/CodeIgniter-reCAPTCHA
(顺便说一句,您的教程 link 不起作用)