6 years ago
Zaid Bin Khalid
7,421 Views
13
Google ReCaptcha is free captcha service by Google. I am going to tell you how you can add Google ReCaptcha to the website. Also, how can you validate reCaptcha using PHP on the server side?
Go to reCaptcha official site and register your reCaptha. Open ReCaptcha link and sign in using your Google account. After sign in you will see below screen.
In Label enter your reCaptcha name. Select reCaptcha version as I select reCAPTCHA V2 with checkbox and I entered label as My ReCaptcha . You can choose your own as per your need.
Then enter domain name without HTTP:// or HTTPS:// complete domain name. Then click on the register button and it is done. 🙂
Below screen will appear after registration.
Follow the second step for the front-end and validation on the server side using below snippet of PHP .
<?php
$userIP = $_SERVER['REMOTE_ADDR'];
$recaptchaResponse = $_REQUEST['g-recaptcha-response'];
$secretKey = "COPY-YOUR-SECRET-KEY-HERE";
$request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secretKey}&response={$recaptchaResponse}&remoteip={$userIP}");
if(!strstr($request, "true")){
echo 'Oppsss reCaptcha is not valid :(';
exit;
}else{
echo 'yahoo reCaptcha is valid :)';
}
?>
6 years ago
Zaid Bin Khalid
7,421 Views
13