简体   繁体   中英

How to Use Captcha my code

How can I Use Captcha in my SendComment code ??

my Captcha Code :

if( empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
        {
            echo $msg .= '<script type="text/javascript">alert("Please Enter Letters Correctly .")</script>';
        }

SendComment code:

function sendcomment(){var cname = document.getElementById('sugname').value;
var qplace = document.getElementById('amountqplace').innerHTML;
var qfood = document.getElementById('amountqfood').innerHTML;
var vfood = document.getElementById('amountvfood').innerHTML;
var text  = document.getElementById('sugtext').value;
var datacom = "cname=" + cname +"&qplace=" + qplace + "&qfood=" + qfood + "&vfood=" + vfood + "&text=" + text;
loadXMLDoc('comment.php?id=<?php echo($uid);?>&type=1','',datacom,1,"Comment Sent Successfully.");

I Want To enter captcha in my SendComment code , if The captcha code enter wrong or didn't enter, Alert "Please Enter Letters Correctly " , and if entered correctly Alert " comment Sent Successfully. "

You need to use AJAX. As I can see, you have your captcha code stored in the session. That is one point.

Now, you need the front end to connect with the backend. Once the user submits the captcha, use AJAX to verify it is the same as the one stored in the session.

Have the front end wait for the response. If the server responds true (or whatever you tell it to respond), allow the form to be submitted. If the server responds false (again whatever you state) then display the alert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM