reCAPTCHA v3の設定を教えてください

実現したいこと

こちらのページを参考にreCAPTCHA v3の設定をしたいのですがうまくいきません。
https://www.webdesignleaves.com/pr/plugins/google_recaptcha.php
php、javascriptに詳しいから教えていただけないでしょうか。
よろしくお願い致します。

※ファイルのコードが膨大なので一部省略しています。

発生している問題・エラーメッセージ

送信しようとすると「このページは動作していません」と表示されます。 エラーコード: sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Class 'ReCaptcha\ReCaptcha' not found in /var/www/www.abc.com/htdocs/inquiry/send.php

該当のソースコード

■ファイル(1) index.html <form id="rc_form"> <button class="c-link-block -center -wide-s" type="submit"> </form> <script src="https://www.google.com/recaptcha/api.js?render=[サイトキー]"></script> <script> window.addEventListener('DOMContentLoaded', function(){ //フォーム要素に submit イベントを設定 $('#rc_form').submit(function(event) { //デフォルトの動作(送信)を停止 event.preventDefault(); //トークンを取得 grecaptcha.ready(function() { grecaptcha.execute('[サイトキー]', {action: 'inquiry'}).then(function(token) { //input 要素を生成して値にトークンを設定 $('#rc_form').prepend('<input type="hidden" name="recaptchaResponse" value="' + token + '">'); //input 要素を生成して値にアクション名を設定 $('#rc_form').prepend('<input type="hidden" name="action" value="homepage">'); //unbind で一度 submit のイベントハンドラを削除してから submit() を実行 $('#rc_form').unbind('submit').submit(); });; }); }); }) </script> ■ファイル(2) send.php <?php $secret = 'abc'; $recaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $recaptcha->setExpectedHostname('example.com') ->setExpectedAction('homepage') ->setScoreThreshold(0.5) ->verify($gRecaptchaResponse, $remoteIp); if ($resp->isSuccess()) { // Verified! 認証成功 } else { $errors = $resp->getErrorCodes(); }

コメントを投稿

0 コメント