JezK
Edit File: login.php
<?php include('mainHeader.php'); $page = basename($_SERVER['PHP_SELF']); if (isset($_POST['action']) && $_POST['action'] == 'userlogin') { $login = $users->login($_POST); if ($login == 1) { if (isset($_POST['cid']) && $_POST['cid'] != '') { echo "<script>window.location='list.php?cid=" . $_POST['cid'] . "'</script>"; } else if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { echo "<script>window.location='professionalsList.php?pid=" . $_REQUEST['pid'] . "'</script>"; } else { echo "<script>window.location='index.php'</script>"; } } elseif ($login == -2) { echo "<script>alert('Your account is blocked please contact admin');</script>"; } elseif ($login == 0) { echo "<script>alert('Invalid Username/Password');</script>"; } else { $userID = $users->getUsers('username', $_POST['username']); $otpsent = $users->sendOtp($userID['0']['country_code'], $userID['0']['mobile'], $userID['0']['id']); $id = $users->encrypt_decrypt('encrypt', $userID['0']['id']); echo "<script>alert('please verify your mobile');window.location='otp.php?mid=" . $id . "'</script>"; } } if (isset($_POST['action']) && $_POST['action'] == "forgetpwd") { $forgetpwd = $users->userForgetPassword($_POST); if ($forgetpwd) { echo "<script>alert('Password has been sent to your registered email/mobile.');</script>"; } elseif ($forgetpwd == -1) { echo "<script>alert('Internal server error');</script>"; } else { echo "<script>alert('Given details does not exist');</script>"; } } ?> <section class="mt-5 pt-4 loginUser-margin top-margin"> <div class="container-fluid bg-white text-dark border"> <div class="row p-4"> <div class="col-sm-8 col-md-5 col-lg-4 col-xl-3 side-border"> <img src="img/illustration1.png" width="250px" height="250px"> </div> <div class="col-sm-8 col-md-7 col-lg-8 col-xl-9"> <ul class="nav nav-tabs border-0"> <li class="nav-item"> <a class="nav-link anc-Colorcurrent <?php if ($page == 'login.php') { echo 'active'; } else { echo ''; } ?>" href="login.php">Login</a> </li> <li class="nav-item"> <a class="nav-link anc-Colorcurrent <?php if ($page == 'signup.php') { echo 'active'; } else { echo ''; } ?>" href="signup.php">Sign up</a> </li> </ul> <!-- login --> <?php $logurl = isset($_REQUEST['cid']) ? "?cid=" . $_REQUEST['cid'] : (isset($_REQUEST['pid']) ? "?pid=" . $_REQUEST['pid'] : ""); ?> <div class="row mt-4"> <div class="col-sm-8 col-md-8 col-lg-6 col-xl-6"> <form action="login.php<?php echo $logurl; ?>" method="POST"> <!-- <h6 class="mt-4 mb-5 style-login fancy-underline">Login</h6> --> <div class="form-group"> <label for="username" class="fieldName">Username</label> <input type="text" class="form-control formField-control" name="username" id="username"> </div> <div class="form-group"> <label for="password" class="fieldName">Password</label> <input type="password" class="form-control formField-control" name="password" id="password"> </div> <div class="form-group "> <!--<input type="checkbox" id="test3" > <label for="test3" class="fieldName">Remember Me</label>--> <a href="" data-toggle="modal" data-target="#myModal" class="float-right fieldName-forgot">Forgot Password?</a> </div> <div class="form-group "> <input type="checkbox" id="loginWithOtp" name="otpLogin" class="custom-control-input" value="value2"> <label for="loginWithOtp" class="custom-control-label remember fieldName pt-1" data-toggle="modal" data-target="#otpModel">Login with OTP instead password</label> </div> <input type="hidden" name="action" value="userlogin"> <input type="hidden" name="cid" value="<?php echo isset($_REQUEST['cid']) ? $_REQUEST['cid'] :''; ?>"> <input type="hidden" name="pid" value="<?php echo isset($_REQUEST['pid']) ? $_REQUEST['pid'] :''; ?>"> <div class="form-group mb-5"> <button class="btn basic-btn-color w-100" onclick="return loginValidation();">Login</button> </div> <div class="form-group"> <p style="text-align: center; font-size: small;">version: 2.2</p> </div> </form> </div> </div> <!-- login --> </div> </div> </div> </section> <?php include('mainFooter.php') ?> <div class="container"> <!-- The Modal --> <div class="modal" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <!-- Modal Header --> <div class="modal-header border-0"> <button type="button" class="close px-2 pt-2 pb-0" data-dismiss="modal">×</button> </div> <!-- Modal body --> <div class="modal-body mx-4"> <h5 class="modal-title style-login mb-3">Forgot Password</h5> <p class="modal-font"> Enter your registerd email/ mobile number. We will send you mail to recover your password</p> <!--start password Form --> <form action="" method="POST"> <div class="form-group"> <label for="forgetemail" class="fieldName">Email ID / Mobile</label> <input type="text" class="form-control formField-control" name="forgetemail" id="forgetemail"> </div> <div class="form-group"> <button class="btn basic-btn-color w-100" onclick="return forgetEmail();">Submit</button> </div> <input type="hidden" name="action" value="forgetpwd"> </form> <!--end password Form --> </div> </div> </div> </div> <!--//////////////////Login With OTP Password////////--> <div class="container"> <!-- The Modal --> <div class="modal" id="otpModel"> <div class="modal-dialog"> <div class="modal-content"> <!-- Modal Header --> <div class="modal-header border-0"> <button type="button" class="close px-2 pt-2 pb-0" data-dismiss="modal">×</button> </div> <!-- Modal body --> <div class="modal-body mx-4"> <h5 class="modal-title style-login mb-3">Login with OTP</h5> <p class="modal-font"> Enter your registerd mobile number. We will send otp for Login</p> <!--start password Form --> <form action="" method="POST"> <div class="form-group"> <label for="otpmobile" class="fieldName">Mobile</label> <input type="number" class="form-control formField-control" name="otpmobile" id="otpmobile" min="0" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" type="number" maxlength="15" minlength="5"> </div> <div class="form-group"> <input type="hidden" name="action" value="sendotp"> <button class="btn basic-btn-color w-100" onclick="return sendotp();">Submit</button> </div> </form> <!--end password Form --> </div> </div> </div> </div> </div> <script type="text/javascript"> function loginValidation() { if ($('#username').val() == '') { alert('Please enter username'); return false; } if ($('#password').val() == '') { alert('Please enter password'); return false; } } function forgetEmail() { var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if ($('#forgetemail').val() == '') { alert('Please enter email/mobile'); return false; } else if (isNaN($('#forgetemail').val())) { var email = $('#forgetemail').val(); var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (reg.test(email) == false) { alert("Please enter valid email address"); return false; } } else { var phoneno = /^\d{5,15}$/; if (!$('#forgetemail').val().match(phoneno)) { alert("Please enter valid Mobile Number"); return false; } } } function sendotp() { if ($('#otpmobile').val() == '') { alert('Please enter mobile number'); return false; } else { var phoneno = /^\d{5,15}$/; if (!$('#otpmobile').val().match(phoneno)) { alert("Please enter valid Mobile Number"); return false; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { console.log(this.responseText); if (this.readyState == 4 && this.status == 200) { if(this.responseText == -7){ alert('Your account has been deleted by admin. Please contact administrator.');return false; } else if(this.responseText == -2){ alert('Your account has been blocked by admin. Please contact administrator.');return false; } else { if (this.responseText == 0) { alert("OTP sending failed"); return false; } else if (this.responseText == -1) { alert('Given mobile number not exist'); return false; } else { var resval= this.responseText; alert('Successfully sent otp to given mobile number'); window.location = 'otp.php?mid=' + resval + '<?php echo isset($_REQUEST['cid']) ? '&cid=' . $_REQUEST['cid'] : (isset($_REQUEST['pid']) ? '&pid=' . $_REQUEST['pid'] : '');?>'; return false; } return false; } return false; } }; xmlhttp.open("GET", "ajax.php?action=sendopt&mobile=" + $('#otpmobile').val(), true); xmlhttp.send(); return false; } return false; } return false; } $("#otpModel .close").click(function() { $("#loginWithOtp").prop("checked", false); }) function redirectFunCall(data){ alert(data+"--Hello To Hi--"); window.location = 'otp.php?mid=' +data; } </script>