how to validate the otp from sms whether the otp entered on the website is correct using php and js?

Viewed 15

THis php file sends a otp(4 digit numeric value) to user and validates it via javascript that if the user has entered the right info or the wrong value.the problem is that whenever the user enters the value either right or wrong it shows that it's wrong.

<?php
include("include/connection.php");
if($_POST['type']=='otpval'){
session_start();
@$otp= $_POST['otp'];
$mobile= $_SESSION["signup_mobile"];
$sessionotp= $_SESSION["signup_otp"]; 
if(strlen($sessionotp!==$otp))  
{
    echo"0";}else{ 
$_SESSION["signup_mobilematched"] = $_SESSION["signup_mobile"];
unset($_SESSION["signup_mobile"]);
unset($_SESSION["signup_otp"]); 
        echo"1";}
}
}
$response = curl_exec($curl);
$err = curl_error($curl); 
curl_close($curl); 
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>

that sends an otp(4 digit numeric value) to user as text message and when the user inputs the value, and clicks a submit button, a javascript(jquery) function

$("#otpsubmitForm").on('submit',(function(e) {
e.preventDefault();
var otp = $('input#otp').val();     
if ((otp)== "") {
            $("input#otp").focus();
            $('#otp').addClass('borderline');
            return false;
            }
        $.ajax({
            type: "POST", 
            url: "veryfynumberNow.php",              
            data: new FormData(this), 
            contentType: false,       
            cache: false,             
            processData:false,       
            success: function(html)   
            { //alert(html);
            var arr = html.split('~');
            if (arr[0]== 1) {
            $("#otpclose").click(); 
    document.getElementById('regtoast').innerHTML = ('<font size="2" style="color:#000;">OTP match successfully !</font>');
            $('#registertoast').modal({backdrop: 'static', keyboard: false})     
            }   
            else if(arr[0]==0)
            { document.getElementById('regtoast').innerHTML = ('<font size="2" style="color:#f00;">Wrong OTP Entered !</font>');
                }           
            }
        });

validates the value entered and shows the result. but whenever i try typing even the right code, it keeps showing wrong value/code entered.Can anyone please help Me To Solve the problem?. thank you for any help!

0 Answers
Related