Skip to content

Instantly share code, notes, and snippets.

@Hothi-Jimit
Forked from kaplanmaxe/mail.php
Created July 19, 2019 07:36
Show Gist options
  • Save Hothi-Jimit/658e5c2b14e7f2cb64ced90dafec0019 to your computer and use it in GitHub Desktop.
Save Hothi-Jimit/658e5c2b14e7f2cb64ced90dafec0019 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>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment