reCaptcha errors
Posted: 2023-01-10 20:49
I followed the instructions in this article, https://bigprof.com/appgini/tips-and-tu ... -recaptcha and now I get this error:
Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\tcp\hooks\__global.php on line 8.
How do I fix this?
TD
Here is the code in __global.php file:
Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\tcp\hooks\__global.php on line 8.
How do I fix this?
TD
Here is the code in __global.php file:
Code: Select all
<?php
// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks
// reCaptcha config
include(__DIR__ . '/reCaptcha.config.php');
Â
// invalidate login if reCAPTCHA is invalid
if ( Request::val('signIn')
  && Request::val('username')
  && Request::val('password')
  && !validRecaptcha() ) {
  unset($_REQUEST['username']);
  unset($_REQUEST['password']);
  unset($_REQUEST['signIn']);
  redirect('index.php?loginFailed=1');
}
Â
function validRecaptcha() {
  // get reCAPTCHA response from login form
  $reCaptchaResponse = Request::val('g-recaptcha-response');
  if(!$reCaptchaResponse) return false;
Â
  if(!function_exists('curl_init')) return false;
Â
  // send a POST request to Google's reCAPTCHA validation API endpoint
  $ch = curl_init();
  curl_setopt_array($ch, [
    CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query([
      'secret' => RECAPTCHA_SECRET_KEY,
      'response' => $reCaptchaResponse,
    ]),
    CURLOPT_RETURNTRANSFER => true,
  ]);
Â
  $googleRespJson = curl_exec($ch);
  curl_close($ch);
Â
  // if error response, abort
  if($googleRespJson === false) return false;
  $googleResp = @json_decode($googleRespJson, true);
  if($googleResp === null) return false;
Â
  return !empty($googleResp['success']);
}
function login_ok($memberInfo, &$args) {
return '';
}