Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
Created February 3, 2017 12:28
Show Gist options
  • Save marcosnakamine/14bf22a68dc40158c341ec47962cead6 to your computer and use it in GitHub Desktop.
Save marcosnakamine/14bf22a68dc40158c341ec47962cead6 to your computer and use it in GitHub Desktop.
PHP - Google Recaptcha
<?php
if ( isset( $_POST['g-recaptcha-response'] ) ) {
// ENVIA INFORMAÇÕES POR POST PARA TESTAR O CAPTCHA
$result = file_get_contents( 'https://www.google.com/recaptcha/api/siteverify', false, stream_context_create( array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query( array(
'response' => $_POST['g-recaptcha-response'],
'secret' => '6LfrOwcTAAAqwAAPLs7mGIKHlBw4qwfcKTJR9tVY_g-Dr'
) ),
),
) ) );
$result = json_decode( preg_replace("/\n|\r| /", "", $result ) );
if ( $result->success ) {
// COLOQUE AQUI AS FUNÇÕES DO PHPMAILER
}
}
?>
<form method="post">
<input type="text">
<div class="g-recaptcha" data-sitekey="6LfrOwcTAqwgAAAAAGiqET2vLM2h84QdqwgC1w8hj0WyuB"></div>
<script type="text/javascript"
src="https://www.google.com/recaptcha/api.js?hl=pt-BR">
</script>
<button>enviar</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment