[英]Is it possible to use google recaptcha on client side without server side support? If possible how?
目前,我正在處理 Nuxtjs 2 項目,我必須在客戶端實現 Recaptcha,我不希望后端支持 Recaptcha。 我只想在前端處理它。 在有或沒有任何與 nuxtjs2 兼容的庫的情況下,我如何在前端執行此操作?
沒有服務器就沒有理由使用 reCAPTCHA。 reCAPTCHA 用於保護后端免受垃圾郵件的侵害。
如果你真的想這樣做,你可以用JavaScript提出同樣的要求。
但同樣:沒有意義。
PHP 的 reCAPTCHA 驗證:
function validate_captcha_response($code){
if($_SERVER['HTTP_HOST']=="localhost") return true;
if($code && strlen($code)>32){
$secret = "<your reCaptcha v3 secret>";
$ip = $_SERVER['REMOTE_ADDR'];
$gcaptcha = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$code&remoteip=$ip"), true);
return ($gcaptcha['success'] == true && $gcaptcha['score'] >= 0.8 && $gcaptcha['hostname'] == $_SERVER['SERVER_NAME']);
}
return false;
}
JavaScript 中的相同代碼:
function validate_captcha_response(code){
if(window.location.hostname=="localhost") return true;
if(code && code.length>32){
let secret = "<your reCaptcha v3 secret>";
let gcaptcha = json_decode(file_get_contents(`https://www.google.com/recaptcha/api/siteverify?secret=${secret}&response=${code}`), true);
return (gcaptcha['success'] == true && gcaptcha['score'] >= 0.8 && gcaptcha['hostname'] == window.location.hostname);
}
return false;
}
(請注意我刪除了 IP 功能)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.