How do I install recaptcha v2 in PHP

First of all, for anyone interested in Reaptcha I leave the link of the article.

In any case, to answer your question, I think the only problem in your code is that you have placed the name of the class with a “$” in front of it.

Change this:

$reCaptcha = new $reCaptcha($secret);

For this other:

$reCaptcha = new reCaptcha($secret);

These codes that I put below work fine.

  1. For the HTML part

< meta http-equiv="X-UA-Compatible" content="ie=edge"> Document

  1. For PHP verification.

Important: You have to include the reCaptcha library, so that ReCaptcha class is available. The logical thing to do that part would be to do it with Composer, and use the autoload system, but that depends on your project. You can also copy and paste the class code.

Then the verification code is this:

$secret = “***SECRET KEY***”; $reCaptcha = newReCaptcha($secret); // Initialize the reCAPTCHA response to null $resp = null; // Has a captcha response been received? if ($_POST) { $resp = $reCaptcha->verifyResponse( $_SERVER, $_POST ); } if ($resp != null && $resp->success) { echo “The captcha response was positive, you are not a robot!!”; } else { echo “We have not received a positive response from the captcha”; }

See also  /faq/que-es-dsn
Loading Facebook Comments ...
Loading Disqus Comments ...