File manager - Edit - /home/familylifersmpc/htdocs/www.familylifersmpc.com/includes/reCaptcha.php
Back
<?php require 'vendor/autoload.php'; // Include Google Cloud dependencies using Composer use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient; use Google\Cloud\RecaptchaEnterprise\V1\Event; use Google\Cloud\RecaptchaEnterprise\V1\Assessment; use Google\Cloud\RecaptchaEnterprise\V1\TokenProperties\InvalidReason; /** * Create an assessment to analyze the risk of a UI action. * @param string $recaptchaKey The reCAPTCHA key associated with the site/app * @param string $token The generated token obtained from the client. * @param string $project Your Google Cloud Project ID. * @param string $action Action name corresponding to the token. */ function create_assessment( string $recaptchaKey, string $token, string $project, string $action ): void { // Create the reCAPTCHA client. // TODO: Cache the client generation code (recommended) or call client.close() before exiting the method. $client = new RecaptchaEnterpriseServiceClient(); $projectName = $client->projectName($project); // Set the properties of the event to be tracked. $event = (new Event()) ->setSiteKey($recaptchaKey) ->setToken($token); // Build the assessment request. $assessment = (new Assessment()) ->setEvent($event); try { $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; } // 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:'); printf($response->getRiskAnalysis()->getScore()); } else { printf('The action attribute in your reCAPTCHA tag does not match the action you are expecting to score'); } } catch (exception $e) { printf('CreateAssessment() call failed with the following error: '); printf($e); } } // TODO: Replace the token and reCAPTCHA action variables before running the sample. create_assessment( '6LfQh-EpAAAAAG_Zo-eC3C6g0Qac_DzqM3ptr-Ze', 'YOUR_USER_RESPONSE_TOKEN', 'polar-caldron-313418', 'YOUR_RECAPTCHA_ACTION' ); ?><?php require 'vendor/autoload.php'; // Include Google Cloud dependencies using Composer use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient; use Google\Cloud\RecaptchaEnterprise\V1\Event; use Google\Cloud\RecaptchaEnterprise\V1\Assessment; use Google\Cloud\RecaptchaEnterprise\V1\TokenProperties\InvalidReason; /** * Create an assessment to analyze the risk of a UI action. * @param string $recaptchaKey The reCAPTCHA key associated with the site/app * @param string $token The generated token obtained from the client. * @param string $project Your Google Cloud Project ID. * @param string $action Action name corresponding to the token. */ function create_assessment( string $recaptchaKey, string $token, string $project, string $action ): void { // Create the reCAPTCHA client. // TODO: Cache the client generation code (recommended) or call client.close() before exiting the method. $client = new RecaptchaEnterpriseServiceClient(); $projectName = $client->projectName($project); // Set the properties of the event to be tracked. $event = (new Event()) ->setSiteKey($recaptchaKey) ->setToken($token); // Build the assessment request. $assessment = (new Assessment()) ->setEvent($event); try { $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; } // 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:'); printf($response->getRiskAnalysis()->getScore()); } else { printf('The action attribute in your reCAPTCHA tag does not match the action you are expecting to score'); } } catch (exception $e) { printf('CreateAssessment() call failed with the following error: '); printf($e); } } // TODO: Replace the token and reCAPTCHA action variables before running the sample. create_assessment( '6LfQh-EpAAAAAG_Zo-eC3C6g0Qac_DzqM3ptr-Ze', 'YOUR_USER_RESPONSE_TOKEN', 'polar-caldron-313418', 'YOUR_RECAPTCHA_ACTION' ); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.26 |
proxy
|
phpinfo
|
Settings