I have a form which has Google's reCAPTCHA. But I am having trouble with the json format returned by it: In the documentation,
https://developers.google.com/recaptcha/docs/verify#api-request :
{
"success": true|false,
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
}
But I am getting this response:
{
"success": true,
"challenge_ts": "2016-06-13T06:46:40Z",
"hostname": "devs.mysite.com.au"
} {"success":false,"errors":[null]}'
Resulting some error . My code is:
$is_valid = $_POST['g-recaptcha-response'];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$fields = array(
'secret' => 'mysecretcode',
'response' => $is_valid,
'remoteip', ''
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);