├── .gitignore ├── Recaptcha.php ├── admin.php ├── config.php ├── login.php └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | -------------------------------------------------------------------------------- /Recaptcha.php: -------------------------------------------------------------------------------- 1 | config = require('config.php'); 23 | } 24 | 25 | public function verifyResponse($recaptcha){ 26 | 27 | $remoteIp = $this->getIPAddress(); 28 | 29 | // Discard empty solution submissions 30 | if (empty($recaptcha)) { 31 | return array( 32 | 'success' => false, 33 | 'error-codes' => 'missing-input', 34 | ); 35 | } 36 | 37 | $getResponse = $this->getHTTP( 38 | array( 39 | 'secret' => $this->config['secret-key'], 40 | 'remoteip' => $remoteIp, 41 | 'response' => $recaptcha, 42 | ) 43 | ); 44 | 45 | // get reCAPTCHA server response 46 | $responses = json_decode($getResponse, true); 47 | 48 | if (isset($responses['success']) and $responses['success'] == true) { 49 | $status = true; 50 | } else { 51 | $status = false; 52 | $error = (isset($responses['error-codes'])) ? $responses['error-codes'] 53 | : 'invalid-input-response'; 54 | } 55 | 56 | return array( 57 | 'success' => $status, 58 | 'error-codes' => (isset($error)) ? $error : null, 59 | ); 60 | } 61 | 62 | 63 | private function getIPAddress(){ 64 | if (!empty($_SERVER['HTTP_CLIENT_IP'])) 65 | { 66 | $ip = $_SERVER['HTTP_CLIENT_IP']; 67 | } 68 | elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) 69 | { 70 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; 71 | } 72 | else 73 | { 74 | $ip = $_SERVER['REMOTE_ADDR']; 75 | } 76 | 77 | return $ip; 78 | } 79 | 80 | private function getHTTP($data){ 81 | 82 | $url = 'https://www.google.com/recaptcha/api/siteverify?'.http_build_query($data); 83 | $response = file_get_contents($url); 84 | 85 | return $response; 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /admin.php: -------------------------------------------------------------------------------- 1 | verifyResponse($recaptcha); 8 | 9 | if(isset($response['success']) and $response['success'] != true) { 10 | echo "An Error Occured and Error code is :".$response['error-codes']; 11 | }else { 12 | echo "Correct Recaptcha"; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | '', 5 | 'secret-key' => '' 6 | ]; -------------------------------------------------------------------------------- /login.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | reCAPTCHA demo 7 | 8 | 13 | 14 | 15 |
16 |
17 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # An Unofficial Google Invisible reCAPTCHA PHP library 2 | ### visit https://www.google.com/recaptcha/admin to register your site and get reCAPTCHA API keys. 3 | ### Add your keys in config.php file 4 | ### To get detailed instruction about integration visit https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php 5 | 6 | 7 | 8 | 9 | --------------------------------------------------------------------------------