{"id":153295,"date":"2026-01-19T01:17:57","date_gmt":"2026-01-18T15:17:57","guid":{"rendered":"https:\/\/shop.virtueit.com.au\/?page_id=153295"},"modified":"2026-01-19T01:34:21","modified_gmt":"2026-01-18T15:34:21","slug":"153295-2","status":"publish","type":"page","link":"https:\/\/virtueit.com.au\/shop\/153295-2\/","title":{"rendered":""},"content":{"rendered":"<div class=\"et_pb_section_0 et_pb_section et_section_regular et_flex_section\">\n<div class=\"et_pb_row_0 et_pb_row et_flex_row\">\n<div class=\"et_pb_column_0 et_pb_column et-last-child et_flex_column et_pb_css_mix_blend_mode_passthrough et_flex_column_24_24 et_flex_column_24_24_tablet et_flex_column_24_24_phone\">\n<div class=\"et_pb_code_0 et_pb_code et_pb_module\"><div class=\"et_pb_code_inner\">    <script src=\"https:\/\/www.google.com\/recaptcha\/enterprise.js\" async defer><\/script>\n    <form action=\"\" method=\"POST\">\n      <div class=\"g-recaptcha\" data-sitekey=\"6Lc5mE4sAAAAAEwPDENkB6Qs5N7wihgB64drN8eh\" data-action=\"LOGIN\"><\/div>\n      <br\/>\n      <input type=\"submit\" value=\"Submit\">\n    <\/form><\/div><\/div>\n\n<div class=\"et_pb_code_1 et_pb_code et_pb_module\"><div class=\"et_pb_code_inner\"><?php \nrequire 'vendor\/autoload.php';\n\n\/\/ Include Google Cloud dependencies using Composer\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\Client\\RecaptchaEnterpriseServiceClient;\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\Event;\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\Assessment;\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\CreateAssessmentRequest;\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\TokenProperties\\InvalidReason;\n\n\/**\n  * Create an assessment to analyse the risk of a UI action.\n  * @param string $recaptchaKey The reCAPTCHA key associated with the site\/app\n  * @param string $token The generated token obtained from the client.\n  * @param string $project Your Google Cloud project ID.\n  * @param string $action Action name corresponding to the token.\n  *\/\nfunction create_assessment(\n  string $recaptchaKey,\n  string $token,\n  string $project,\n  string $action\n): void {\n  \/\/ Create the reCAPTCHA client.\n  \/\/ TODO: Cache the client generation code (recommended) or call client.close() before exiting the method.\n  $client = new RecaptchaEnterpriseServiceClient();\n  $projectName = $client->projectName($project);\n\n  \/\/ Set the properties of the event to be tracked.\n  $event = (new Event())\n    ->setSiteKey($recaptchaKey)\n    ->setToken($token);\n\n  \/\/ Build the assessment request.\n  $assessment = (new Assessment())\n    ->setEvent($event);\n\n  $request = (new CreateAssessmentRequest())\n  ->setParent($projectName)\n  ->setAssessment($assessment);\n\n  try {\n    $response = $client->createAssessment($request);\n\n    \/\/ Check if the token is valid.\n    if ($response->getTokenProperties()->getValid() == false) {\n      printf('The CreateAssessment() call failed because the token was invalid for the following reason: ');\n      printf(InvalidReason::name($response->getTokenProperties()->getInvalidReason()));\n      return;\n    }\n\n    \/\/ Check if the expected action was executed.\n    if ($response->getTokenProperties()->getAction() == $action) {\n      \/\/ Get the risk score and the reason(s).\n      \/\/ For more information on interpreting the assessment, see:\n      \/\/ https:\/\/cloud.google.com\/recaptcha-enterprise\/docs\/interpret-assessment\n      printf('The score for the protection action is:');\n      printf($response->getRiskAnalysis()->getScore());\n    } else {\n      printf('The action attribute in your reCAPTCHA tag does not match the action you are expecting to score');\n    }\n  } catch (exception $e) {\n    printf('CreateAssessment() call failed with the following error: ');\n    printf($e);\n  }\n}\n\n\/\/ TO-DO: Replace the token and reCAPTCHA action variables before running the sample.\ncreate_assessment(\n   '6Lc5mE4sAAAAAEwPDENkB6Qs5N7wihgB64drN8eh',\n   'YOUR_USER_RESPONSE_TOKEN',\n   'recaptcha-migrated-8f3efd81aff',\n   'YOUR_RECAPTCHA_ACTION'\n);\n  ?><\/div><\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-153295","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/pages\/153295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/comments?post=153295"}],"version-history":[{"count":0,"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/pages\/153295\/revisions"}],"wp:attachment":[{"href":"https:\/\/virtueit.com.au\/shop\/wp-json\/wp\/v2\/media?parent=153295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}