Home > Backend Development > PHP Tutorial > Regarding verification issues with mobile phone verification codes

Regarding verification issues with mobile phone verification codes

WBOY
Release: 2016-09-09 08:28:03
Original
1363 people have browsed it

When users register, they need to enter some content and give each form a flag value.
When the focus is lost, the flag value of the form is detected.
When the final submission is made, these flag values ​​are correct before submission.
But the problem arises. :
If the user’s focus is now on the verification code input box, and the user clicks the submit button to register after entering the verification code, there is no problem
Because the user moves the mouse from the verification code input box to the submit button, the verification code has been verified Completed, its flag value is already true
However, if the user uses the Enter key to submit and the focus is still on the verification code input box, this requires manual focusout() using code

<code>$("input:focus").focusout();
for(var i=0;i<$("input").length;i++){
    if($("input").eq(i).attr('flag')==0){
        return false;
    }
}</code>
Copy after login
Copy after login

The verification code is placed in the session. At this time, we need to check whether the user's verification code is correct in the background. Before the detection is completed, the flag value of the form is still false. Then the following code is executed and returns false, causing the form to fail. Submit
I also thought about giving the for loop a delay, so that when the user submits, all the things that need to be verified can be verified
But in this case, the user can submit directly without inputting anything, and all the verification at the front desk is done Invalidated
I don’t know if my description is clear enough. If there is anything I haven’t explained clearly, you can leave a message. Thank you everyone

Reply content:

When users register, they need to enter some content and give each form a flag value.
When the focus is lost, the flag value of the form is detected.
When the final submission is made, these flag values ​​are correct before submission.
But the problem arises. :
If the user’s focus is now on the verification code input box, and the user clicks the submit button to register after entering the verification code, there is no problem
Because the user moves the mouse from the verification code input box to the submit button, the verification code has been verified Completed, its flag value is already true
However, if the user uses the Enter key to submit and the focus is still on the verification code input box, this requires manual focusout() using code

<code>$("input:focus").focusout();
for(var i=0;i<$("input").length;i++){
    if($("input").eq(i).attr('flag')==0){
        return false;
    }
}</code>
Copy after login
Copy after login

The verification code is placed in the session. At this time, we need to check whether the user's verification code is correct in the background. Before the detection is completed, the flag value of the form is still false. Then the following code is executed and returns false, causing the form to fail. Submit
I also thought about giving the for loop a delay, so that when the user submits, all those that need to be verified can be verified
But in this case, the user can submit directly without inputting anything, and all the verification at the front desk is done Invalidated
I don’t know if my description is clear enough. If there is anything I haven’t explained clearly, you can leave a message. Thank you everyone

You can execute all the test conditions again when you are about to submit, and then check whether all flags are true.

You can directly submit the input value of the verification code for comparison with the background session. Why do you need to submit a front-end verification mark? Everything submitted on the front end can be forged.

Add an ajax event before you submit, that is, determine whether the verification code is correct, and then submit if it is correct. If it is not correct, a pop-up window will appear, and you will not submit.
You can prevent the above situation.

<code>$("input[type=submit]").click(function(){
    $("input:focus").focusout();
    // 检测延时50s左右
    setTimeout(function(){
        var submitFlag=true;
        // 两个for循环可以抽出一个函数
        for(var i=0;i<$("input").length-2;i++){
            if($("input").eq(i).attr('flag')==0){
                submitFlag=false;
            }
        }
        if(submitFlag){
            $("form").submit();
        }
    },100);
    for(var i=0;i<$("input").length-2;i++){
        if($("input").eq(i).attr('flag')==0){
            return false;
        }
    }
});</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template