私はphpログインファイルを持っており、そのログインフォームにgoogleのcaptchaを入れたいと思います。私は1つのファイル(他のPHPページにフォームデータを送信しない)で一緒にPHPとHTMLを使用します。 問題は、ユーザーがキャプチャを確認せず、ウェブサイトにログインできることです(キャプチャしていなくても確認できます)。ここに私のコードは次のとおりです。Googleのcaptchaが動作しない
<form action="" method="post" id="form">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" class="form-control" name="form-username" id="form-username" placeholder="Username" required="">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" class="form-control" name="form-password" placeholder="Password" id="form-password" required="">
</div>
</div>
<div class="form-group">
<div class="g-recaptcha" data-theme="dark" data-sitekey="my site key"></div>
<div class="form-group no-border margin-top-20">
<input type="submit" name="submit" value="Sign In !" class="submit_button4 btn btn-primary btn-block" >
</form>
<?php
if($_SERVER["REQUEST_METHOD"] === "POST")
{
//form submitted
//check if other form details are correct
//verify captcha
$recaptcha_secret = "my secret key";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$response = json_decode($response, true);
if($response["success"] === true)
{
echo "Logged In Successfully";
}
else
{
echo "You are a robot";
}
}
?>
注:このコード<script src='https://www.google.com/recaptcha/api.js'></script>
が私の頭のタグである(そして、すべてのコードが1ページです)。
私はあなたの質問に答えました。お手伝いしていただきありがとうございます – Jonathan