Aug 23rd, 2017, 8:29 AM
(This post was last modified: Aug 23rd, 2017, 8:34 AM by whatfield73.)
Ok,
1) After you create a recaptcha account with google using the Recaptcha 2.0 method, For the Google Recaptcha on your webpage just use google's code (not the formtools api)
2) Make sure the api is installed as per formtools documentation
3) Change in the process.php and the api.php any mention of the challenge field to "g-recaptcha-response" which is what google passes instead of recaptcha's
For instance: if (isset($g_api_version) && isset($form_data["g-recaptcha-response"]))
4) Put the private and the public key in the correct places in formtools documentation
5) change the recaptcha check answer function to:
function recaptcha_check_answer ($privkey, $remoteip, $challenge){
if ($privkey == null || $privkey == '') {
die ("To use reCAPTCHA you must get an API key from Recaptcha");
}
if ($remoteip == null || $remoteip == '') {
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
}
//error_log($challenge, 0, "formtools/error_log.txt");
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$url="https://www.google.com/recaptcha/api/siteverify";
$result = file_get_contents($url."?secret=".$privkey."&response=".$challenge."&remoteip=".$remoteip);
//error_log($result, 0, "formtools/error_log.txt");
$recaptcha_response = new ReCaptchaResponse();
if ($result['success'] == "true" || $result['success'] == 1 || $result['success'] == TRUE) {
//error_log("true", 0 , "formtools/error_log.txt");
$recaptcha_response->is_valid = true;
}
else {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $result[1];
}
return $recaptcha_response;
}
Last change the function call in process php to:
recaptcha_check_answer($g_api_recaptcha_private_key, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field);
(you may need to do this in the api as well)
It works for me
1) After you create a recaptcha account with google using the Recaptcha 2.0 method, For the Google Recaptcha on your webpage just use google's code (not the formtools api)
2) Make sure the api is installed as per formtools documentation
3) Change in the process.php and the api.php any mention of the challenge field to "g-recaptcha-response" which is what google passes instead of recaptcha's
For instance: if (isset($g_api_version) && isset($form_data["g-recaptcha-response"]))
4) Put the private and the public key in the correct places in formtools documentation
5) change the recaptcha check answer function to:
function recaptcha_check_answer ($privkey, $remoteip, $challenge){
if ($privkey == null || $privkey == '') {
die ("To use reCAPTCHA you must get an API key from Recaptcha");
}
if ($remoteip == null || $remoteip == '') {
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
}
//error_log($challenge, 0, "formtools/error_log.txt");
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$url="https://www.google.com/recaptcha/api/siteverify";
$result = file_get_contents($url."?secret=".$privkey."&response=".$challenge."&remoteip=".$remoteip);
//error_log($result, 0, "formtools/error_log.txt");
$recaptcha_response = new ReCaptchaResponse();
if ($result['success'] == "true" || $result['success'] == 1 || $result['success'] == TRUE) {
//error_log("true", 0 , "formtools/error_log.txt");
$recaptcha_response->is_valid = true;
}
else {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $result[1];
}
return $recaptcha_response;
}
Last change the function call in process php to:
recaptcha_check_answer($g_api_recaptcha_private_key, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field);
(you may need to do this in the api as well)
It works for me