【问题标题】:cakephp + recaptcha issuescakephp + recaptcha 问题
【发布时间】:2013-09-12 18:45:46
【问题描述】:

我正在关注this 教程,了解如何在我的 cakephp2.2.5 项目中添加 recaptcha。不幸的是,每次我点击提交按钮时,我的控制器中都会出现“invalid-request-cookie”错误。这是我控制器中的代码

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);

 }

如果我不使用 ajax 并使用以下代码

$resp = recaptcha_check_answer ('...',
                $_SERVER["REMOTE_ADDR"],
                $this->request->data["recaptcha_challenge_field"],
                $this->request->data["recaptcha_response_field"]);

我的 $resp 变量中出现了同样的错误。 我已经包含了https://www.google.com/recaptcha/api/js/recaptcha_ajax.js。 我也有

echo "<div id='recaptcha_div'></div>";

在我的视图文件中。

我已经试过了

https://github.com/CakeDC/recaptcha

教程,但我得到了更多的错误。所以我求助于简单的教程。任何帮助都会很棒。

【问题讨论】:

    标签: php ajax cakephp recaptcha


    【解决方案1】:

    我认为您正在 localhost 中尝试此代码。如果是这样,那么 api 将无法工作。 api 使用 api 密钥检查 url。因此,如果您使用某个 url 注册并尝试在其他站点上对其进行测试,那么该 api 将无法正常工作。您可以在教程http://blog.jambura.com/2013/01/02/use-recaptcha-in-cakephp-app/?fb_comment_id=fbc_576497325700235_7768923_699586046724695#f2d979a62c中查看此评论

    【讨论】:

      【解决方案2】:

      我求助于使用服务器端检查。我正在同时进行客户端和服务器端检查,因此它为什么不起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-22
        • 1970-01-01
        • 1970-01-01
        • 2017-08-02
        • 2015-02-24
        • 2015-07-26
        相关资源
        最近更新 更多