projectName($project); // Set the properties of the event to be tracked. $event = (new Event()) ->setSiteKey(Configuration::GetConfig("reCAPTCHA", "KeyID")) ->setToken($token); // Build the assessment request. $assessment = (new Assessment())->setEvent($event); $response = $client->createAssessment( $projectName, $assessment ); // Check if the token is valid. if ($response->getTokenProperties()->getValid() == false) { // printf('The CreateAssessment() call failed because the token was invalid for the following reason: '); // printf(InvalidReason::name($response->getTokenProperties()->getInvalidReason())); return floatval(-1); } // Check if the expected action was executed. if ($response->getTokenProperties()->getAction() == $action) { // Get the risk score and the reason(s). // For more information on interpreting the assessment, see: // https://cloud.google.com/recaptcha-enterprise/docs/interpret-assessment // printf('The score for the protection action is:'); return $response->getRiskAnalysis()->getScore(); } else { // printf('The action attribute in your reCAPTCHA tag does not match the action you are expecting to score'); } return null; } public static function HandleCaptchaResponse(string $captchaResponse): void { $assessmentResponse = CAPTCHAWrapper::CreateAssessment( token: $captchaResponse, action: 'submit' ); if ($assessmentResponse == null) { die("captcha assessment is null"); } if ($assessmentResponse <= floatval(Configuration::GetConfig("reCAPTCHA", "AcceptableLowerBoundsForLogin"))) { die("go away robot!"); } SessionWrapper::Set(SessionElement::LAST_ASSESSMENT_RESULT, $assessmentResponse); } }