file_get_contents not returning anything

796 views
Skip to first unread message

ch...@sell-on.com

unread,
Aug 3, 2016, 12:19:08 AM8/3/16
to reCAPTCHA
Having a problem in PHP with file_get_contents site verification.  Symptom: file_get_contents does not return a string from the siteverify service.  Here's the code:
<?php

if(isset($_POST['submit']) && !empty($_POST['submit'])):
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
        
//your site secret key
$secret = 'My Secret Key'; // I'm masking my secret key for privacy, but this is actually the key in the real code

echo nl2br("<b>secret:</b> " .$secret. "\n\n"); //Successfully echos the Secret Key
echo nl2br("<b>g-recaptcha-response: </b>\n" .$_POST['g-recaptcha-response']. "\n\n"); //Successfully echos the g-recaptcha-response

//get verify response data
echo ('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);  //Successfully echos the concatenated URL with secret and response variable filled in - if I copy/paste this into a browser, it returns "success": "challenge_ts": and "hostname": values
echo file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); //THIS ECHOS A "NULL" (BLANK) - THIS IS THE PROBLEM I AM TRYING TO SOLVE FOR

echo nl2br("\n\nEND"); //This was added to confirm that the program is running past the file_get_contents command

//THE FOLLOWING ARE COMMENTED OUT FOR DEBUGGING PURPOSES
//echo nl2br("<b>verifyResponse (file_get_contents): </b>" .$verifyResponse. "\n\n");

//$responseData = json_decode($verifyResponse, true);
//echo nl2br("<b>responseData (json_decode): </b>" .$responseData['success']. "\n\n"); //echos NULL

//if($responseData->success):
//  echo "<b>Success</b>";
//  else:
//    echo "<b>Failed</b>";
//  endif;
  endif;
endif;

?>
..

What am I missing here?  Pulling my hair out and not seeing the error.  Thanks!

Chuck

Seth Munroe

unread,
Aug 6, 2016, 2:30:55 AM8/6/16
to reCAPTCHA
Could there be a firewall preventing your call to the siteveryify url from going out from your server process?

-Seth
Reply all
Reply to author
Forward
0 new messages