Integrate captcha on your own page - how it works
Related Videos: How To Make Contact Form With Captcha | Create Working Contact Form Wtih reCaptcha (May 2024).
In this practical tip you will learn how you can easily integrate a captcha on your website. This enables you to check whether a form has been completed by a robot. In this example we use the "reCAPTCHA" from Google.
Embed Captcha: Register website with Google
To use Google's reCAPTCHA, you need a free Google account.
- Open the reCAPTCHA website in your browser and register your website here.
Integration of the captcha in the head of the website
Add the following Java script to the head of your website:
Integration of the DIV container
Include the following DIV container where you want the captcha to appear:
- Don't forget to replace [website key] with the corresponding website key.
Review of the captcha response
In order to check whether the captcha was solved correctly, an additional field with the name "g-recaptcha-response" is sent in addition to the form. You can query this in PHP, for example, with "$ _POST ['g-recaptcha-response']". Finally, a query with the "secret" and "response" must be sent to the URL "//www.google.com/recaptcha/api/siteverify" in order to compare the response of the Captcha with the Google server. In response, you will receive a JSON script that confirms the correctness of the captcha or, if necessary, not. The return values can be found in the "$ data" variable, which you can then process further. The programming could look like this in PHP:
- $ json = file_get_contents ('// www.google.com/recaptcha/api/siteverify?secret=[ Secret key] & response ='. $ _ POST ['g-recaptcha-response']);
- $ data = json_decode ($ json);
- var_dump ($ data);