1

I am working on an inquiry form for a domains for sale and I implemented google reCaptcha to it. The reCaptcha is working fine on my local server using xampp but when I uploaded it on the server, It always response a success=false even if I I checked the capcha. Here is my code:

    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $privatekey = "KEY"; 

    $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);

    $data = json_decode($response);

    if(isset($data->success) AND $data->success==true){
        //some code
    }
    else{
        //some code
    }

I use a separate key for my local development and for the live one. I believe I use the correct secret key and sitekey when i uploaded it to the server. any idea why this is happening?

Nash
  • 31
  • 3
  • Based on live url generate api key. It will works..! – Elangovan Oct 20 '16 at 11:17
  • Your `$data` object contains an `error-codes` attribute. This will tell you what went wrong. – simon Oct 20 '16 at 11:22
  • I've tried dumping the recaptcha response in my local server but theirs no error-codes – Nash Oct 21 '16 at 00:36
  • Try looking at `var_dump($response)` on both servers. You should *always* see a JSON-formatted string. If not, your HTTPS URL didn't work. For discussion and tests you can do, see [ http://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with-https] – Tom Robinson Mar 22 '17 at 18:59

1 Answers1

0

My first instinct on this one is case sensitivity. Meaning that the directory have been given one (or more) capital letters by Windows. While Windows treats the upper and lower cases as the same, other operating systems don't.

So, I recommend double-checking on the server that all file and directory names are lower-case only. Hopefully that should clear up your problems.

ChristianF
  • 2,068
  • 9
  • 14
  • Case sensitivity could not be the issue here. `file_get_contents("https://...` will be intercepted by PHP and will never be passed to the Windows file system. – Tom Robinson Mar 22 '17 at 18:46