Google Recaptcha v3 example demo

后端 未结 7 928
故里飘歌
故里飘歌 2020-12-02 10:44

Until now, I was working with Google Recaptcha v2, but now I want to update my WebApp using the lastest version (v3).

Is it possible to anyone add a fully working Go

7条回答
  •  醉话见心
    2020-12-02 11:17

    I am assuming you have site key and secret in place. Follow this step.

    In your HTML file, add the script.

     
    

    Also, do use jQuery for easy event handling.

    Here is the simple form.

     






    You need to initialize the Google recaptcha and listen for the ready event. Here is how to do that.

         
    

    Here is the sample PHP file. You can use Servlet or Node or any backend language in place of it.

    Please check the the captcha form.';
              exit;
            }
            $secretKey = "put your secret key here";
            $ip = $_SERVER['REMOTE_ADDR'];
    
            // post request to server
    
            $url =  'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) .  '&response=' . urlencode($captcha);
            $response = file_get_contents($url);
            $responseKeys = json_decode($response,true);
            header('Content-type: application/json');
            if($responseKeys["success"]) {
                    echo json_encode(array('success' => 'true'));
            } else {
                    echo json_encode(array('success' => 'false'));
            }
    ?>
    

    Here is the tutorial link: https://codeforgeek.com/2019/02/google-recaptcha-v3-tutorial/

    Hope it helps.

提交回复
热议问题