Tweet, Share & Like [ EnAcCiOn ]

 

FeedBurner FeedCount Y Facebook | EnAcCiOn

Send Voicemail | EnAcCiOn

Contact me using vCita | EnAcCiOn

Contact me using vCita | EnAcCiOn

Meeting Scheduler Powered by vCita

jueves, 30 de julio de 2015

Response value in noCaptcha reCaptcha always false

My goal is to use google's "noCaptcha reCaptcha" mechanism to verify, if the user is a human on a contact form for a website. I am not a very experienced web developer, so I had to look up several tutorials on PHP and POST-methods. I now got it working to the point, where I do get a response from google, but the value for the "success" element returned by the POST request is always false, even though the graphical element on the webpage says it is fine. The error code returned by the same request is "NULL", which I guess is a good thing. Am I misunderstanding something here? All research on this specific error only turned up cases, where either the response value was not assigned or there has been an error message of some kind. I use google's API (link to the used API) for reCaptcha here, because attempts at sending HTTP-Request objects and using curl flat out did not work. In the first case I guess it is because of missing libraries and in the second case "response" always got a "NULL" value assigned (or rather no value, because this was the default). In the following code parts, $secret is the secret key from google, $response is the code sent by the captcha, gotten from $_POST["g-recaptcha-response"]. The mail code itself works perfectly fine, I tested it seperately before. This is the var_dump output: object(ReCaptchaResponse)#2 (2) { ["success"]=> bool(false) ["errorCodes"]=> NULL } This is the client code: $reCaptcha = new ReCaptcha($secret); if ($response) { $answer = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $response); } else { echo "There has been an error with the authentication"; } var_dump($answer); if ($answer != NULL && $answer->success) { $err = mail($recipient, $subject, $mailtext, implode("\r\n", $headers)); if ($err == false) { echo "The mail could not be sent."; } echo "The E-Mail was sent."; } else { echo "Your identity could not be verified."; }

No hay comentarios:

EnAcCiOn

Contador Web | EnAcCiOn

EnAcCiOn

EnAcCiOn

EnAcCiOn

Blog Archive | EnAcCiOn