在哪里处理 reCAPTCHA?在 JavaScript 或 PHP 中?
Where to handle reCAPTCHA? In JavaScript or in PHP?
我在 web 开发方面的经验几乎为零,但我找到了 simple example of a contact form with reCAPTCHA and trying to figure out how to make it work on my WordPress site. There is the 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(...) 和 returns "OK",但不清楚在这种情况下如何检查验证码?谁检查它,JavaScript 或 PHP?
这是我使用的class方法。当您使用 javascript
提交验证码时,参数 ($gRecaptchaResponse) 是 google 返回的内容
protected function validateGoogleRecaptcha($gRecaptchaResponse)
{
$secretKey = $this->config['application']['captcha']['recaptcha']['secretKey'];
$reCaptcha = new \ReCaptcha($secretKey);
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$gRecaptchaResponse
);
return $response;
}
我在 web 开发方面的经验几乎为零,但我找到了 simple example of a contact form with reCAPTCHA and trying to figure out how to make it work on my WordPress site. There is the 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(...) 和 returns "OK",但不清楚在这种情况下如何检查验证码?谁检查它,JavaScript 或 PHP?
这是我使用的class方法。当您使用 javascript
提交验证码时,参数 ($gRecaptchaResponse) 是 google 返回的内容protected function validateGoogleRecaptcha($gRecaptchaResponse)
{
$secretKey = $this->config['application']['captcha']['recaptcha']['secretKey'];
$reCaptcha = new \ReCaptcha($secretKey);
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$gRecaptchaResponse
);
return $response;
}