Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src='https://www.google.com/recaptcha/api.js'></script>
- <div class="g-recaptcha" data-sitekey="6LeC6VQUAAAAAPRIpR4DJ_8RhqqpvedXWGRMQl7l"></div>
- <?php
- function post_captcha($user_response) {
- $fields_string = '';
- $fields = array(
- 'secret' => '6LeC6VQUAAAAALubXKUQAo-KMamUxhlJM4Ddeud9',
- 'response' => $user_response
- );
- foreach($fields as $key=>$value)
- $fields_string .= $key . '=' . $value . '&';
- $fields_string = rtrim($fields_string, '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
- $result = curl_exec($ch);
- curl_close($ch);
- return json_decode($result, true);
- }
- // Call the function post_captcha
- $res = post_captcha($_POST['g-recaptcha-response']);
- if (!$res['success']) {
- // What happens when the CAPTCHA wasn't checked
- echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
- } else {
- // If CAPTCHA is successfully completed...
- // Paste mail function or whatever else you want to happen here!
- echo '<br><p>CAPTCHA was completed successfully!</p><br>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement