I'm following this tutorial on how to add recaptcha on my cakephp2.2.5 project. Unfortunately everytime I hit the submit button I keep getting the " invalid-request-cookie" error in my controller. Here's the code in my controller
if ($this -> request -> is('post')) {
$url = 'http://www.google.com/recaptcha/api/verify';
$ch = curl_init($url);
$post = array("privatekey" => "...",
"remoteip" => $_SERVER["REMOTE_ADDR"],
"challenge"=>$this->request->data["recaptcha_challenge_field"],
"response" => $this->request->data["recaptcha_response_field"]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
}
If I dont use ajax and use the following code
$resp = recaptcha_check_answer ('...',
$_SERVER["REMOTE_ADDR"],
$this->request->data["recaptcha_challenge_field"],
$this->request->data["recaptcha_response_field"]);
I get the same error in my $resp variable. I have included https://www.google.com/recaptcha/api/js/recaptcha_ajax.js already. I also have
echo "<div id='recaptcha_div'></div>";
in my View file.
I've already tried following
tutorial but that one I got more errors. So I'm resorting to the easy tutorial. ANy help would be great.