php - Google recaptcha v3 พร้อม codeigniter 3 - captcha-sol ไม่ถูกต้อง

ฉันพยายามเพิ่ม recaptchav3 ในเว็บไซต์ของฉันซึ่งสร้างขึ้นจาก codeigniter 3 ด้วย php8 แต่ฉันได้รับข้อผิดพลาด captcha-sol ไม่ถูกต้องเมื่อฉันส่งคำตอบ ใครสามารถช่วยฉันแก้ไขสิ่งต่อไปนี้ ?


// รหัสไซต์ที่กำหนดไว้ใน config/constants.php


define(\'SITE_KEY\',\'XXXXXXX\');
define(\'SECRET_KEY\',\'XXXXXX\');

my_view :


<!-- some html header code -->
<?php $site_key=SITE_KEY;?>
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo $site_key; ?>" async defer></script>
</head>

<form name="news_form" id="news_form" action="<?=site_url(\'account/store_profile\'); ?>" method="post" onsubmit="return(validateForm());">
<div class="input-cover f5" style="display: none;">
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" />
<input type="hidden" id="action" name="action" />
<!--- other elements -->
<button type="submit" name="submit" class="button" id="submit">Send</button>
<button type="reset" name="reset" class="button cancel" id="cancel">Cancel</button>
</form>
<?php $site_key= SITE_KEY;?>
<script type="text/javascript">
grecaptcha.ready(function() {
grecaptcha.execute(\'<?php echo $site_key; ?>\', {action: \'profile\'})
.then(function(token) {
console.log(token);
document.getElementById(\'g-recaptcha-response\').value=token;
document.getElementById(\'action\').value=\'profile\';
});
});
</script>


คอนโทรลเลอร์:


if (isset($_POST[\'submit\'])) {
$data=$this->input->post();

//form validation code here $this->form_validation->set_rules
$arrResponse = getCaptcha($data[\'g-recaptcha-response\'],$data[\'action\']); // call to helper function

if($arrResponse["success"] == \'1\' && $arrResponse["action"] == $action && $arrResponse["score"] >= 0.5) {
// valid submission
// go ahead and do necessary stuff
} else {
// spam submission
// show error message
}


common_helper.php


< รหัส>function getCaptcha($token,$action){
if(isset($token) && !empty($token)) {
$secret_key = SECRET_KEY;
$Response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret_key."&response=".$token."&remoteip=" . $_SERVER[\'REMOTE_ADDR\']);
$Return = json_decode($Response);
echo "<pre>";print_r($Response);exit;


ข้อผิดพลาด :


{
"success": false,
"error-codes": [
"incorrect-captcha-sol"
]
}

Answer

วิธีแก้ไข:

วิธีนี้แก้ไขได้ นี่คือวิธีแก้ปัญหา
แทนที่จะกำหนดคำหลักคงที่ให้กับตัวแปร php ฉันได้ echo คำหลักคงที่โดยตรง


Source