在哪里办理reCAPTCHA?在JavaScript或PHP?

问题描述 投票:-3回答:1

我在网络开发方面的经验几乎为零,但我找到了一个与reCAPTCHA联系的simple example,并试图弄清楚如何让它在我的WordPress网站上运行。有live demo

是否有可能在index.js中实现'submit'函数,它检查验证码,异步发送表单数据并处理响应?

new Vue({
  // root node
  el: "#app",
  // the instance state
  //...
  methods: {
    // submit form handler
    submit: function() {
      this.submitted = true;
    },
  //..
});

如果是,服务器端可以有一个处理请求的PHP脚本,调用mail(...)并返回“OK”,但是在这种情况下如何检查验证码并不清楚?谁检查它,JavaScript或PHP?

php vue.js recaptcha
1个回答
0
投票

这是我使用的类方法。参数($ gRecaptchaResponse)是谷歌使用javascript提交验证码时返回的内容

protected function validateGoogleRecaptcha($gRecaptchaResponse)
{

    $secretKey = $this->config['application']['captcha']['recaptcha']['secretKey'];
    $reCaptcha = new \ReCaptcha($secretKey);

    $response = $reCaptcha->verifyResponse(
        $_SERVER["REMOTE_ADDR"],
        $gRecaptchaResponse
    );

    return $response;
}
© www.soinside.com 2019 - 2024. All rights reserved.