JezK
Edit File: otp.php
<?php include('mainHeader.php'); $page = basename($_SERVER['PHP_SELF']); // include('classes/class_users.php'); // $users=new Users(); $id = $users->encrypt_decrypt('decrypt', $_REQUEST['mid']); // echo $id;exit; $userdet = $users->getusers('id', $id); // print_r($userdet);exit; $redirectURL='index.php'; if (isset($_REQUEST['cid']) && $_REQUEST['cid'] != '') { $redirectURL='list.php?cid=' . $_REQUEST['cid'] ; } else if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $redirectURL='professionalsList.php?pid=' . $_REQUEST['pid'] ; } ?> <section class="mt-5 pt-4 mx-5 loginUser-margin"> <div class="container-fluid bg-white text-dark border"> <div class="row p-4 justify-content-center align-items-center"> <div class="col col-sm-8 col-md-8 col-lg-6 col-xl-5"> <!--<form action="" method="POST">--> <h6 class="mt-4 mb-5 style-login justify-content-center d-flex">Login with OTP</h6> <div class="form-group"> <div class="row"> <label for="username" class="fieldName col-6">We have sent you an otp on</label> <!-- <div class="col-6"><a href="" class="text-primary justify-content-end d-flex fs-13">Change Number</a></div> --> </div> <div class="row"> <div class="col-6"> <p class="fs-13">+<?php echo $userdet['0']['country_code'] . ' ' . $userdet['0']['mobile'] ?></p> </div> <!-- <div class="col-6"><a href="" class="text-primary justify-content-end d-flex fs-13">Change Number</a></div> --> </div> <!-- <input type="text" class="form-control formField-control" name="email" id="username"> --> </div> <div class="form-group"> <label for="otp" class="fieldName">OTP</label> <input type="number" class="form-control formField-control" name="otp" id="otp" min="0"> <span class="text-dark fs-13">Still not received OTP</span> <a href="javascript:void(0);" class="fs-13" style="color:#00c0f0" onclick="resendOtp('<?php echo $_REQUEST['mid']; ?>')">Resend Otp</a> </div> <div class="form-group mb-4"> <input type="hidden" name="action" value="otpverification"> <input type="hidden" name="uid" id="uid" value="<?php echo $id; ?>"> <input type="hidden" name="mobilenum" id="mobilenum" value="<?php echo $userdet['0']['mobile']; ?>"> <button class="btn basic-btn-color w-100" onclick="return verifyotp()">Verify OTP</button> </div> <!--</form>--> </div> </div> </div> </div> </section> <?php include('mainFooter.php') ?> <script type="text/javascript"> function resendOtp(mid) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (this.responseText == 1) { alert("Successfully sent otp to your mobile number"); return false; } else if (this.responseText == 0) { alert("OTP sending failed"); return false; } } }; xmlhttp.open("POST", "ajax.php?mid=" + mid + "&action=resendotp", true); xmlhttp.send(); } function verifyotp() { if ($('#otp').val() == '') { alert("Please enter otp"); return false; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (this.responseText == 1) { alert("Successfully verified."); window.location = '<?php echo $redirectURL;?>'; return false; } else if (this.responseText == -1) { alert("OTP mismatched"); return false; } else if (this.responseText == -2) { alert("OTP not existed please resend otp"); return false; } else if (this.responseText == -3) { alert("User Details not existed "); window.location = 'login.php'; } else if (this.responseText == -4) { alert("Given otp already verified"); window.location = 'login.php'; } else if (this.responseText == 0) { alert("OTP verification failed"); return false; } } }; xmlhttp.open("POST", "ajax.php?mid=<?php echo $_REQUEST['mid']; ?>&mobile=" + $('#mobilenum').val() + "&action=verifyotp&otp=" + $('#otp').val(), true); xmlhttp.send(); } } </script>