bu2chlc

Google reCAPTCHA php page

Sep 30th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. if($_POST){
  2.     //this funtion sends your secret key and the token to get a json object response
  3.     //with info about the form submission.
  4.     function getCaptcha($SecretKey){
  5.         $Response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".SECRET_KEY."&response={$SecretKey}");
  6.         $Return= json_decode($Response);
  7.         return $Return;
  8.         //for testing, you can run the following line to see the response from Google:
  9.             var_dump($Response);
  10.          }
  11.     //here we are actually sending the info with the token...
  12.     $Return=getCaptcha($_POST[g-recaptcha-response]);
  13.      //if the return is success and the score is over 0.5 run your code!
  14.      if($Return->success == true && $Return->score > 0.5){
  15. //run your code here when submission is NOT a BOT...
  16.     } else {
  17.         echo "you are a bot and the world hates you";
  18.     }
  19. }
Add Comment
Please, Sign In to add comment