แต่ติดปัญหาที่ว่า
หากรอบนั้นมีการเลือกมากกว่า 1 ภาพแล้วจะได้ค่า token จาก recaptcha แค่ 1 อัน แต่พอเข้าไฟล์ upload จะเช็คค่า token ได้แค่ภาพแรกอันเดียว
>> ต้องปรับ code ส่วนไหน ที่จะเช็คค่า token เดิมในรอบที่กดเลือกภาพได้ค่ะ
ไฟล์ index.php หน้าทำ upload ไฟล์
โค้ด: เลือกทั้งหมด
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo $keyrecaptcha_v3?>"></script>
<script>
function getrecap(){
grecaptcha.ready(function () {
grecaptcha.execute('<?php echo $keyrecaptcha_v3?>', {action: 'contact'}).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
}
</script>
<!------ส่วนฟอร์ม upload รูป----->
<form id="upload" method="post" action="upload.php" enctype="multipart/form-data" >
<input type="hidden" name="recaptcha_response_check" id="recaptchaResponse">
<div class="row">
<div class="col-md-3" > </div>
<div class="col-md-6">
<div id="drop">
<a onclick="getrecap()"><img src="./assets/img/upload2.png" style="width:35%"><br>'.$lang_insert_file.'</a>
<input type="file" name="upl" multiple />
</div>
</div>
<div class="col-md-3"> </div>
</div>
<div class="row">
<div class="col-md-12" id="div_load">
<ul > </ul>
</div>
</div>
</form>
โค้ด: เลือกทั้งหมด
$recaptchaResponse = !empty($_REQUEST['recaptcha_response_check']) ? $_REQUEST['recaptcha_response_check'] : '';
//-------------------------------
if(!empty($recaptchaResponse)){
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $secretkeyrecaptcha_v3 . '&response=' . $recaptchaResponse);
$recaptcha = json_decode($recaptcha);
if ($recaptcha->success) {
// Verified – send email
$make_convert='Y';
} else { //print_r($recaptcha);
$make_convert='N';
}
}else{
$make_convert='N';
}