Skip to content

Instantly share code, notes, and snippets.

@kaplanmaxe
Last active May 7, 2020 05:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kaplanmaxe/b3e4fe4ee3e286a4f8d815660daa57e2 to your computer and use it in GitHub Desktop.
Save kaplanmaxe/b3e4fe4ee3e286a4f8d815660daa57e2 to your computer and use it in GitHub Desktop.
PHP Recaptcha PHP tutorial
<?php
$sender_name = stripslashes($_POST["sender_name"]);
$sender_email = stripslashes($_POST["sender_email"]);
$sender_message = stripslashes($_POST["sender_message"]);
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'YOUR_SECRET',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
@jrsconfitto
Copy link

Thanks for this!

@anil5594
Copy link

anil5594 commented Apr 9, 2018

Hi this side is Anil i have a problem with this code my server hosting PHP version is PHP 5.6.35 and form link is http://aischool.in/form/contact.php not working on this site but on another hosting account with PHP version: 7.1.14 for this form http://studyonlinehelp.com/contact2.php same code is running successfully.
so can you suggest me what is the exact problem is it php version problem or any other problem.

thanks in Advance.

@BillyCroan
Copy link

$response is never used. I would recommend using it in line 10, or deleting line 5.

@computekie
Copy link

ok half the code is missing... ???

@ichsanni
Copy link

ichsanni commented May 7, 2020

Thanks for the tutorial! I was messing with recaptcha but don't know what or how to utilise it, now I understand. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment