本文整理汇总了PHP中ReCaptcha类的典型用法代码示例。如果您正苦于以下问题:PHP ReCaptcha类的具体用法?PHP ReCaptcha怎么用?PHP ReCaptcha使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReCaptcha类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logon
public function logon()
{
require_once "../third_party/recaptchalib.php";
// busca a biblioteca recaptcha
$secret = "6LcgGhcTAAAAAHXSiMR1BT4pg183Ix6UEsoCBvgw";
// sua chave secreta
$response = null;
// resposta vazia
$reCaptcha = new ReCaptcha($secret);
// verifique a chave secreta
// se submetido, verifique a resposta
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
}
if ($response != null && $response->success) {
$this->load->model('Usuarios_model');
$user = $this->Usuarios_model->searchByUser($this->input->post("user"));
if ($user) {
$pass = $this->input->post("pass");
if (md5($pass) != $user['pass']) {
$this->session->set_flashdata('danger', 'Senha incorreta!');
} else {
$this->session->set_userdata('logged', $user);
}
} else {
$this->session->set_flashdata('danger', 'Usuário não encontrado!');
}
}
redirect("/");
}
示例2: testVerifyReturnsResponse
public function testVerifyReturnsResponse()
{
$method = $this->getMock('\\ReCaptcha\\RequestMethod', array('submit'));
$method->expects($this->once())->method('submit')->with($this->callback(function ($params) {
return true;
}))->will($this->returnValue('{"success": true}'));
$rc = new ReCaptcha('secret', $method);
$response = $rc->verify('response');
$this->assertTrue($response->isSuccess());
}
示例3: 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;
}
示例4: valid
/**
* Validates a reCaptcha response from a user.
*
* @param string reCaptcha response
* @return boolean
*/
public function valid($response)
{
if (empty($response)) {
return FALSE;
}
require_once Kohana::find_file('vendor', 'recaptchalib');
$reCaptcha = new ReCaptcha(Captcha::$config['privateKey']);
$responseCaptcha = $reCaptcha->verifyResponse($this->get_real_user_ip(), $response);
if ($responseCaptcha == null || false == $responseCaptcha->success) {
return FALSE;
}
return TRUE;
}
示例5: validate_post
/**
* Check that the CAPTCHA was entered correctly. reCAPTCHA sets a long string in 'g-recaptcha-response'
* when the CAPTCHA is completed; we check that with the reCAPTCHA API.
*/
public function validate_post(&$error)
{
require_once $this->directory . 'recaptchalib.php';
$recaptcha = new ReCaptcha(qa_opt('recaptcha_private_key'));
$remoteIp = qa_remote_ip_address();
$userResponse = qa_post_text('g-recaptcha-response');
$recResponse = $recaptcha->verifyResponse($remoteIp, $userResponse);
foreach ($recResponse->errorCodes as $code) {
if (isset($this->errorCodeMessages[$code])) {
$error .= $this->errorCodeMessages[$code] . "\n";
}
}
return $recResponse->success;
}
示例6: index
public function index()
{
//Google reCaptcha
//updated to Google noCaptcha 1/15
require_once CORE_LIB_PATH . '/recaptcha/recaptchalib.php';
$this->set('sitekey', RECAPTCHA_PUBLIC_KEY);
$this->set('lang', 'en');
if ($this->post->submit) {
if (Auth::LoggedIn() == false) {
# Make sure they entered an email address
if (trim($this->post->name) == '' || trim($this->post->email) == '') {
$this->set('message', 'You must enter a name and email!');
$this->render('core_error.tpl');
return;
}
}
//Google reCaptcha
//updated to Google noCaptcha 1/15
$resp = null;
$reCaptcha = new ReCaptcha(RECAPTCHA_PRIVATE_KEY);
// Was there a reCAPTCHA response?
if ($_POST["g-recaptcha-response"]) {
$resp = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
}
//check if reCaptcha response was valid
if ($resp == null) {
$this->set('captcha_error', 'reCaptcha Validation Error');
$this->render('contact_form.tpl');
return;
}
//end Google reCaptcha
if ($this->post->subject == '' || trim($this->post->message) == '') {
$this->set('message', 'You must enter a subject and message!');
$this->render('core_error.tpl');
return;
}
$subject = 'New message from ' . $this->post->name . ' - "' . $this->post->subject . '"';
$message = DB::escape($this->post->message) . PHP_EOL . PHP_EOL;
foreach ($_POST as $field => $value) {
$message .= "-{$field} = {$value}" . PHP_EOL;
}
$message = nl2br($message);
$message = utf8_encode($message);
Util::SendEmail(ADMIN_EMAIL, $subject, $message);
$this->render('contact_sent.tpl');
return;
}
$this->render('contact_form.tpl');
}
示例7: check_captcha_validation
public function check_captcha_validation($errors)
{
$options = WPPlugin::retrieve_options('recaptcha_options');
if (empty($_POST['g-recaptcha-response']) || $_POST['g-recaptcha-response'] == '') {
$errors->add('blank_captcha', $options['no_response_error']);
return $errors;
}
$reCaptchaLib = new ReCaptcha($options['secret']);
$response = $reCaptchaLib->verifyResponse($_SERVER['REMOTE_ADDR'], $_POST['g-recaptcha-response']);
// response is bad, add incorrect response error
if (!$response->success) {
$errors->add('captcha_wrong', $response->error);
}
return $errors;
}
示例8: 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.");
}
}
示例9: verify
public static function verify()
{
$siteKey = "6LfLpgETAAAAALJh3IVzXccKgCXG-yTlNYaLTL26";
$secret = "6LfLpgETAAAAAG7XXCVIbvqR1QClWiJ86D0bsnTs";
// reCAPTCHA supported 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
$lang = "en";
// The response from reCAPTCHA
$resp = null;
// The error code from reCAPTCHA, if any
$error = null;
$reCaptcha = new ReCaptcha($secret);
// Was there a reCAPTCHA response?
if ($_POST["g-recaptcha-response"]) {
$resp = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
}
}
示例10: the_alias_works
/**
* @test
*/
public function the_alias_works()
{
$rendered = \ReCaptcha::render();
$expected = '<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey=""></div>
';
$this->assertEquals($expected, $rendered);
}
示例11: validate_re_captcha
/**
* reCaptcha Validation
*
* @return void
*/
function validate_re_captcha($no_captcha = '')
{
$private_key = wpuf_get_option('recaptcha_private', 'wpuf_general');
if ($no_captcha == 1) {
$response = null;
$reCaptcha = new ReCaptcha($private_key);
$resp = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
if (!$resp->success) {
$this->send_error(__('reCAPTCHA validation failed', 'wpuf'));
}
} elseif ($no_captcha == 0) {
$recap_challenge = isset($_POST['recaptcha_challenge_field']) ? $_POST['recaptcha_challenge_field'] : '';
$recap_response = isset($_POST['recaptcha_response_field']) ? $_POST['recaptcha_response_field'] : '';
$resp = recaptcha_check_answer($private_key, $_SERVER["REMOTE_ADDR"], $recap_challenge, $recap_response);
if (!$resp->is_valid) {
$this->send_error(__('reCAPTCHA validation failed', 'wpuf'));
}
}
}
示例12: captcha
function captcha()
{
$par = JComponentHelper::getParams('com_djclassifieds');
$app = JFactory::getApplication();
$token = JRequest::getCMD('token', '');
$token_link = $token ? '&token=' . $token : '';
if ($par->get('captcha_type', 'recaptcha') == 'nocaptcha') {
require_once JPATH_COMPONENT . DS . 'assets' . DS . 'nocaptchalib.php';
} else {
require_once JPATH_COMPONENT . DS . 'assets' . DS . 'recaptchalib.php';
}
$privatekey = $par->get('captcha_privatekey', "6LfzhgkAAAAAAOJNzAjPz3vXlX-Bw0l-sqDgipgs");
$is_valid = false;
if ($par->get('captcha_type', 'recaptcha') == 'nocaptcha') {
$response = null;
$reCaptcha = new ReCaptcha($privatekey);
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
if ($response != null && $response->success) {
$is_valid = true;
}
}
} else {
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$is_valid = $resp->is_valid;
}
if ($is_valid) {
$session =& JFactory::getSession();
$session->set('captcha_sta', '1');
$message = '';
} else {
$message = JText::_("COM_DJCLASSIFIEDS_INVALID_CODE");
}
$menus = JSite::getMenu();
$menu_newad_itemid = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=additem', 1);
$new_ad_link = 'index.php?option=com_djclassifieds&view=additem';
if ($menu_newad_itemid) {
$new_ad_link .= '&Itemid=' . $menu_newad_itemid->id;
}
$new_ad_link = JRoute::_($new_ad_link . $token_link);
$app->redirect($new_ad_link, $message, 'error');
}
示例13: frontend_validate
/**
* {@inheritdoc}
*/
public function frontend_validate(array $item, $input_value)
{
$mesages = array('not-configured' => __('Could not validate the form', 'fw'), 'not-human' => __('Please fill the recaptcha', 'fw'));
$keys = fw_ext('forms')->get_db_settings_option('recaptcha-keys');
if (empty($keys)) {
return $mesages['not-configured'];
}
$recaptcha = new ReCaptcha($keys['secret-key']);
$gRecaptchaResponse = FW_Request::POST('g-recaptcha-response');
if (empty($gRecaptchaResponse)) {
return $mesages['not-human'];
}
$resp = $recaptcha->verify($gRecaptchaResponse);
if ($resp->isSuccess()) {
return false;
} else {
$errors = $resp->getErrorCodes();
return $mesages['not-human'];
}
}
示例14: validate
public function validate($retType)
{
parent::validate($retType);
copyArray($_POST, $fv, 'name', 'email', 'msg');
if (trim($fv['name']) == '') {
$rets[] = array('msg' => 'Please enter your name!', 'field' => 'name');
}
if (filter_var($fv['email'], FILTER_VALIDATE_EMAIL) === FALSE) {
$rets[] = array('msg' => 'Invalid email!', 'field' => 'email');
}
if (trim($fv['msg']) == '') {
$rets[] = array('msg' => 'Please enter your message!', 'field' => 'msg');
}
if (ReCaptcha::checkAnswer() == false && isset($retType) && $retType == RT_JSON) {
$rets[] = array('msg' => 'The reCAPTCHA wasn\'t entered correctly!', 'field' => 'recaptcha');
}
if (isset($retType) && $retType == RT_JSON && isset($rets)) return outputJson($rets);
return $rets;
}
示例15: get_errors
/**
*
* Get different possible errors before registering an user
* @return Array errors
*/
public function get_errors()
{
$constraints = new \CODOF\Constraints\User();
$constraints->username($this->username);
$constraints->password($this->password);
$constraints->mail($this->mail);
$errors = $constraints->get_errors();
if (\CODOF\Util::get_opt('captcha') == "enabled") {
require_once ABSPATH . 'sys/Ext/recaptcha/recaptchalib.php';
$privatekey = \CODOF\Util::get_opt("captcha_private_key");
// your secret key
$secret = $privatekey;
// empty response
$response = null;
// check secret key
$reCaptcha = new \ReCaptcha($secret);
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
}
if (!($response != null && $response->success)) {
$errors[] = _t("capcha entered was wrong");
}
}
return $errors;
}