📌  相关文章
📜  recaptcha v3 (1)

📅  最后修改于: 2023-12-03 15:34:41.555000             🧑  作者: Mango

reCAPTCHA v3

reCAPTCHA v3 is a free service provided by Google that helps protect your website or application from spam and abuse. It uses advanced risk analysis techniques to detect humans and bots.

How it works

reCAPTCHA v3 is designed to work as a background service that constantly monitors website or application usage. When a user interacts with your website or application, reCAPTCHA v3 silently assesses the risk level of the interaction based on various factors such as the user's IP address, browsing history, and mouse movements.

If the interaction is determined to be low-risk, reCAPTCHA v3 will passively allow the user to continue without any interruption. If the interaction is determined to be high-risk, reCAPTCHA v3 will trigger a challenge that asks the user to prove that they are not a bot.

Getting started

To use reCAPTCHA v3 on your website or application, you will need to sign up for a free reCAPTCHA API key from Google. Once you have the API key, you can add the necessary code to your website or application to start using reCAPTCHA v3.

Adding reCAPTCHA v3 to a web page

To add reCAPTCHA v3 to a web page, you will need to:

  1. Include the reCAPTCHA JavaScript library in your HTML code:

    <script src="https://www.google.com/recaptcha/api.js?render=YOUR_SITE_KEY"></script>
    
  2. Add a reCAPTCHA badge to your page:

    <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY" data-action="ACTION_NAME"></div>
    

    Replace YOUR_SITE_KEY with your reCAPTCHA API key and ACTION_NAME with the name of the action that the user is taking (e.g. "submit_form").

  3. Call the grecaptcha.execute() method in your JavaScript code whenever the user performs the action:

    grecaptcha.ready(function() {
        grecaptcha.execute('YOUR_SITE_KEY', {action: 'ACTION_NAME'}).then(function(token) {
            // Do something with the token
        });
    });
    

    This method will return a token that you can use to verify that the user is not a bot.

Conclusion

reCAPTCHA v3 is a powerful tool that can help protect your website or application from spam and abuse. By using advanced risk analysis techniques, reCAPTCHA v3 can silently filter out bots while allowing legitimate users to continue using your website or application without any interruption. If you haven't already, sign up for a free reCAPTCHA API key from Google and start using reCAPTCHA v3 today!