weixin_33717298 2013-09-12 18:45 采纳率: 0%
浏览 20

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.

  • 写回答

2条回答 默认 最新

  • weixin_33749242 2013-09-14 04:39
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题