cakephp + Recaptcha问题

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

https://github.com/CakeDC/recaptcha

tutorial but that one I got more errors. So I'm resorting to the easy tutorial. ANy help would be great.

I think you are tring this code in localhost. if so then the api will not work. api check the url with the api key. So if you sign up with a certain url and try to test it on other site then the api will not work. You can check this comment in the tutorial http://blog.jambura.com/2013/01/02/use-recaptcha-in-cakephp-app/?fb_comment_id=fbc_576497325700235_7768923_699586046724695#f2d979a62c

I resorted to using the server-side check. I was doing both client and server side check hence why it wasnt working.