本文整理汇总了PHP中ReCaptcha::recaptcha_check_answer方法的典型用法代码示例。如果您正苦于以下问题:PHP ReCaptcha::recaptcha_check_answer方法的具体用法?PHP ReCaptcha::recaptcha_check_answer怎么用?PHP ReCaptcha::recaptcha_check_answer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReCaptcha
的用法示例。
在下文中一共展示了ReCaptcha::recaptcha_check_answer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateUserInput
public function validateUserInput()
{
if (Str::nullOrEmpty($this->name)) {
$this->addError("generic.error.missingRequiredField", array('field' => 'name'), 'name');
}
if (Str::nullOrEmpty($this->contents)) {
$this->addError("generic.error.missingRequiredField", array('field' => 'contents'), 'contents');
}
if (Str::nullOrEmpty($this->blogId)) {
$this->addError("generic.error.missingRequiredField", array('field' => 'blogId'));
}
// check captcha
if (!Str::nullOrEmpty($this->captchaChallenge)) {
$resp = ReCaptcha::recaptcha_check_answer(self::CAPTCHA_PRIVATE_KEY, $_SERVER["REMOTE_ADDR"], $this->captchaChallenge, $this->captchaResponse);
if ($resp->is_valid) {
// DAY is in milliseconds, convert to seconds and multiply by 14 for 2 weeks
$expireTime = time() + GlobalConstants::DAY / 10 * 14;
setcookie(self::CAPTCHA_COOKIE_NAME, true, $expireTime, '/');
} else {
$this->addError($resp->error);
}
} elseif (!isset($_COOKIE[self::CAPTCHA_COOKIE_NAME])) {
$this->addError("Captcha does not appear to be functioning properly, please contact site administrator.");
}
}
示例2: check
/**
* Check if a captcha value is valid
*
* @access public
* @return bool return validity of captcha value
*/
function check()
{
$recaptcha = jaws()->request->fetch(array('recaptcha_challenge_field', 'recaptcha_response_field'), 'post');
if ($recaptcha['recaptcha_response_field']) {
$privatekey = $GLOBALS['app']->Registry->fetch('reCAPTCHA_private_key', 'Policy');
$objReCaptcha = new ReCaptcha();
$objReCaptcha->recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $recaptcha['recaptcha_challenge_field'], $recaptcha['recaptcha_response_field']);
return $objReCaptcha->is_valid;
}
return false;
}