简体   繁体   English

如何使用验证码我的代码

[英]How to Use Captcha my code

How can I Use Captcha in my SendComment code ?? 如何在我的SendComment代码中使用验证码?

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: SendComment代码:

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. " 我想在我的SendComment代码中输入验证码,如果验证码输入错误或未输入,则警报“请正确输入字母”,如果输入正确,则警报“注释已成功发送”。

You need to use AJAX. 您需要使用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. 用户提交验证码后,请使用AJAX验证其与会话中存储的验证码相同。

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. 如果服务器响应为true(或您要求其响应的任何响应),则允许提交表单。 If the server responds false (again whatever you state) then display the alert. 如果服务器响应为假(再次声明),则显示警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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