I think you just have a typo. You have a “$” before response in your URL string so it is being interpreted as a PHP variable which at present is undefined. That should instead be an ampersand(&).
That may not be the only issue, but is the first thing I see.
I have a Contact Form in my website where I have included a reCAPTCHA. The client-side is working; however, the server-side has an issue. The server-side integration page of the Google reCAPTCHA website provides a table of the secret key, response, and remoteip. I have included them in my code but I don’t know what to include as the response since the table says:
response: Required. The user response token provided by the reCAPTCHA
client-side integration on your site.
Here is my PHP code:
$secretKey="";
$responseKey=$_POST['g-recaptcha-response'];
$UserIP = $_SERVER['REMOTE_ADDR'];
$url="...siteverify?secret=$secretKey$response=$responseKey&remoteip=$UserIP";
$response = file_get_contents($url);
$response = json_decode($response);
if($response->success){
do something
}
else{
Display error message
}
Currently, this is not working and the code is doing the else part of the if, even if the user is verified. I am not sure about the value of $response so I am guessing that that is the problem. How can I fix this issue?
Is it because of $response? If so, what value should I give to $response here:
$responseKey=$_POST['g-recaptcha'];