Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Google Recaptcha

I am trying to test this.

I went to Google, got the keys, copied each one & pasted into my test code VERY CAREFULLY.

The first one works, the 2nd one (secret key) does not.

I am at a loss about what to do,

I am using this code for the processing program (php). Obviously the "secret code" is not the real one. Is this processing code correct or is there an error?
<?php
        $email;$comment;$captcha;
        if(isset($_POST['email'])){
          $email=$_POST['email'];
        }if(isset($_POST['comment'])){
          $email=$_POST['comment'];
        }if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please check the the captcha form.</h2>';
          exit;
        }
        $secretKey = "thesecretcode";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<h2>You are spammer ! Get the @$%K out</h2>';
        } else {
          echo '<h2>Thanks for posting comment.</h2>';
        }
?>

Open in new window


I get the "You are a spammer......." response.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

It would be a lot easier to read your code if you would use the industry standards for indentation.  When it's a jumble like that, it's hard to tease out the meaning and intent.

Please post a link to the docs you followed, and I'll try to do the same.  If I can get it to work, I'll post back with an example.
Avatar of Richard Korts

ASKER

Ray, I copied that code from a place I found yesterday. Not sure I can re-find, I will try.
Ray, here is the link:

https://codeforgeek.com/2014/12/google-recaptcha-tutorial/

Seemed simple enough to me.

Thanks
Thanks - I'll start on it!
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nope, does not work.

There must be something wrong with the 2nd key.

Sounds like that's a black hole with no way out, so I'll have to try something else.

Probably your simple arithmetic, seems that is good.

Thanks
Thanks for your efforts.

Is there any way I can get the Google Recaptcha keys reset? Obviously, something is wrong with what I have.
I don't know how to "reset" the keys but you can find them this way.

https://www.google.com/recaptcha/admin#list 

Click on the name of your site under Your reCAPTCHA sites

Click on "Keys" under Adding reCAPTCHA to your site

It shows the keys.  You can copy/paste them.
Ray, I figured out how to get new keys, still don't work, I OF COURSE copied & pasted.

I am showing the client your random arithmetic cpatcha; they might go for that. The only issue I see with it is if the answer is 14, for example, they have to type in Fourteen, right, they can't just put in 14.

Or can they, I did not examine the code?

Thanks,

Richard
Try it both ways.  I'm pretty sure I made it so it would work with the number of the text.

When you say "still don't work" are you using the script I posted?
I am using your script VERBATIM, I copied it.

I can email it to you as is if you like.

It says I am a spammer.

I can't waste anymore time on this. I realize millions of web sites use it, I am doing something dumb that makes it fail.

Thanks for your efforts.

Richard
Yes, please email it.  Ray.Paseur [at] Gmail.com, thanks.  One possible thing... IIRC the key set is only valid for a given URL, so if you got a key in one domain and tried to use it in another domain it should not work.
There may be some confusion caused by multiple accounts.  I cannot figure out a way to get rid of a reCaptcha account, but you can change the label of the account to something like "junk" and change the domain to something that you do not use (maybe example.com).  Do that for all of the accounts you want to get rid of.  Then add a new account and use the keys Google gives you for the new account.  I've never tried doing this, but it seems like the intuitive thing.  Best of luck, Ray