Ejemplo n.º 1
0
 function gglcptch_check()
 {
     global $gglcptch_options;
     if (!gglcptch_get_allow_url_fopen() && isset($gglcptch_options['recaptcha_version']) && $gglcptch_options['recaptcha_version'] == 'v2') {
         return array('response' => false, 'reason' => 'ERROR_ALLOW_URL_FOPEN');
     }
     $publickey = $gglcptch_options['public_key'];
     $privatekey = $gglcptch_options['private_key'];
     if (!$privatekey || !$publickey) {
         return array('response' => false, 'reason' => 'ERROR_NO_KEYS');
     }
     $gglcptch_remote_addr = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
     if (isset($gglcptch_options['recaptcha_version']) && 'v2' == $gglcptch_options['recaptcha_version']) {
         $gglcptch_g_recaptcha_response = '';
         if (!isset($_POST["g-recaptcha-response"])) {
             return array('response' => false, 'reason' => 'RECAPTCHA_NO_RESPONSE');
         } elseif (empty($_POST["g-recaptcha-response"])) {
             return array('response' => false, 'reason' => 'RECAPTCHA_EMPTY_RESPONSE');
         } else {
             $gglcptch_g_recaptcha_response = stripslashes(esc_html($_POST["g-recaptcha-response"]));
         }
         require_once 'lib_v2/recaptchalib.php';
         $reCaptcha = new gglcptch_ReCaptcha($privatekey);
         $resp = $reCaptcha->verifyResponse($gglcptch_remote_addr, $gglcptch_g_recaptcha_response);
         if ($resp != null && $resp->success) {
             return array('response' => true, 'reason' => '');
         } else {
             return array('response' => false, 'reason' => 'VERIFICATION_FAILED');
         }
     } else {
         $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = '';
         if (!isset($_POST['recaptcha_challenge_field']) && !isset($_POST['recaptcha_response_field'])) {
             return array('response' => false, 'reason' => 'RECAPTCHA_NO_RESPONSE');
         } elseif (!empty($_POST['recaptcha_challenge_field']) && empty($_POST['recaptcha_response_field'])) {
             return array('response' => false, 'reason' => 'RECAPTCHA_EMPTY_RESPONSE');
         } else {
             $gglcptch_recaptcha_challenge_field = stripslashes(esc_html($_POST['recaptcha_challenge_field']));
             $gglcptch_recaptcha_response_field = stripslashes(esc_html($_POST['recaptcha_response_field']));
         }
         require_once 'lib/recaptchalib.php';
         $resp = gglcptch_recaptcha_check_answer($privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field);
         if (!$resp->is_valid) {
             return array('response' => false, 'reason' => 'VERIFICATION_FAILED');
         } else {
             return array('response' => true, 'reason' => '');
         }
     }
 }
Ejemplo n.º 2
0
 function gglcptch_captcha_check()
 {
     $gglcptch_options = get_option('gglcptch_options');
     $privatekey = $gglcptch_options['private_key'];
     if (isset($gglcptch_options['recaptcha_version']) && 'v2' == $gglcptch_options['recaptcha_version']) {
         require_once 'lib_v2/recaptchalib.php';
         $reCaptcha = new gglcptch_ReCaptcha($privatekey);
         $gglcptch_g_recaptcha_response = isset($_POST["g-recaptcha-response"]) ? $_POST["g-recaptcha-response"] : '';
         $resp = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $gglcptch_g_recaptcha_response);
         if ($resp != null && $resp->success) {
             echo "success";
         } else {
             echo "error";
         }
     } else {
         require_once 'lib/recaptchalib.php';
         $gglcptch_recaptcha_challenge_field = isset($_POST['recaptcha_challenge_field']) ? $_POST['recaptcha_challenge_field'] : '';
         $gglcptch_recaptcha_response_field = isset($_POST['recaptcha_response_field']) ? $_POST['recaptcha_response_field'] : '';
         $resp = gglcptch_recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field);
         if (!$resp->is_valid) {
             echo "error";
         } else {
             echo "success";
         }
     }
     die;
 }