{
"success": true|false,
"score": number,
"action": string,
"challenge_ts": timestamp,
"hostname": string,
"error-codes": [...]
}
<?php
.
.
.
// post request to verify token with Google reCaptcha server
//
$url = "https://www.google.com/recaptcha/api/siteverify";
$data = array (
'secret' => $secretKey,
'response' => $captcha,
);
// use key 'http' even if request is to https://...
//
$options = array (
'http' => array (
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$responseKeys = json_decode($response, true);
// echo $responseKeys[success];
// echo $responseKeys[action];
//echo $responseKeys[score];
if($responseKeys["success"] == true && $responseKeys["action"] == $action && $responseKeys["score"] >= 0.5) {
echo ("reCaptcha.php thinks you are human");
header ("location: ./sent-success.htm");
} else {
echo ("reCaptcha.php thinks you are a bot");
header ("location: ./spam-block.htm");
}
?>
file_put_contents('debug.log',print_r($responseKeys, true));
And then check the debug.log file in the same folder as the primary script.
$result = print_r($responseKeys);
echo $result.'\r\n<br>';
Which resulted in console.log displaying 1\r\n<br>. Is this telling me that success and action variables are empty, and score is equal to 1? Or is the code malformed? Obviously not what I want.file_put_contents('debug.log',print_r($responseKeys, true));
and looked at FF debugger window, which was empty? When you say "in the same folder as the primary script," I'm assuming I need to be in the recaptcha.php directory? Tried the 'command+P' FIND FILE but only showed js files. Probably, I need to read up on using the debugger.<b>Warning</b>: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in <b>D:\inetpub\themagnolia\reCaptcha.php</b> on line <b>58</b><br />
<br />
<b>Warning</b>: file_get_contents(https://www.google.com/recaptcha/api/siteverify): failed to open stream: no suitable wrapper could be found in <b>D:\inetpub\themagnolia\reCaptcha.php</b> on line <b>58</b><br />
It looks like your preferred method "file_put_contents('debug.Not exactly, this errorlog', print_r($responseKeys, true));" isn't working because of PHP server settings. I'm getting error messages
b>Warning</b>: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in <b>D:\inetpub\themagnolia\Has nothing to do with my debug statement. The debug uses file_PUT_contents - this is referring to file_GET_contents and is a very common message on shared hosting.reCaptcha. php</b> on line <b>58</b><br />
Open in new window