Finally I solved Google reCaptcha problem.
I was followed exactly what's Shahid Shaikh wrote in his article - google-recaptcha-tutorial
But then I am getting empty response.
$url = 'https://www.google.com/recaptcha/api/siteverify?secret='. urlencode($secretKey) .'&response='. urlencode($captcha);
$response = file_get_contents($url);
I knew the problem is on file_get_contents($url), because I tried to put the URL into browser and its 100% working well.
Uhmmmmm..................
Then I tried to change it to using PHP CURL.
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL ='https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST = true,
CURLOPT_POSTFIELDS = [
'secret' = $secretKey,
'response' = $captcha,
'remoteip' = $_SERVER['REMOTE_ADDR']
],
CURLOPT_RETURNTRANSFER = true
]);
$response = curl_exec($ch);
curl_close($ch);
$responseKeys = json_decode($response,true);
Its work perfectly with PHP CURL.
No comments:
Post a Comment