How to send otp and verify it (in wordpress)?
Send otp and verify it (in wordpress)
//send otp part <div class="container"> <center> <h4>Enter Mobile Number</h4> <form method="post" action=""> <input type="text" class="fullrow" name="phone" placeholder="Enter phone no." > <span class="error" style="display:none"></span> <input class="submit" type="submit" value="Get OTP" name="sotp"> </form> </center> </div> <span class="success" style=""></span> <script> jQuery(document).ready(function($){ $(".submit").click(function(e){ e.preventDefault(); var number = $(".fullrow").val(); //alert(number); var data = { 'action':'otp_send', 'number':number, } $.post(myajax.ajaxurl,data,function(response){ $(".success").html(response); }); }); });
//verify otp part <div class="container"> <center> <h4>Verify OTP</h4> <form method="post" action=""> <input type="text" class="fullrow1" name="otp" placeholder="Enter OTP" > <span class="error" style="display:none"></span> <input class="submit1" type="submit" value="Submit OTP" name="votp"> </form> </center> </div> <span class="success1" style=""></span> <script> jQuery(document).ready(function($){ $(".submit").click(function(e){ e.preventDefault(); var number = $(".fullrow").val(); //alert(number); var data = { 'action':'otp_send', 'number':number, } $.post(myajax.ajaxurl,data,function(response){ $(".success").html(response); }); }); });
// function.php part function dashboard(){ echo '<script LANGUAGE="JavaScript">window.location.href="'.site_url().'/home-movies/";</script>'; } function verifyotp(){ echo '<script LANGUAGE="JavaScript">window.location.href="'.site_url().'/verify-otp/";</script>'; } function otp_send(){ $pnumber = $_POST['number']; global $wpdb; $table_name = $wpdb->prefix . "my_plugintable"; $results = $wpdb->get_results("select * from $table_name where phone=$pnumber "); $count_result = count($results); if($count_result > 0){ //cookie set $otp = rand(100000, 999999); setcookie('otp', $otp, time()+62208000, '/', $_SERVER['HTTP_HOST']); // Authorisation details. $username = "sandipstud@gmail.com"; $hash = "274162474fefea10be75c903a636e74fcf1fcab1d3b1751bc5735075346aef5f"; // Config variables. Consult http://api.textlocal.in/docs for more info. $test = "0"; // Data for text message. This is the text message data. $sender = "TXTLCL"; // This is who the message appears to be from. $numbers = "7005974177"; // A single number or a comma-seperated list of numbers $message = " Yout OTP Is :" . $otp; // 612 chars or less // A single number or a comma-seperated list of numbers $message = urlencode($message); $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test; $ch = curl_init('http://api.textlocal.in/send/?'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); // This is the result from the API curl_close($ch); verifyotp(); } die(); } add_action('wp_ajax_nopriv_otp_send','otp_send'); add_action('wp_ajax_otp_send','otp_send'); function otp_verify(){ $otp1 = $_POST['otp']; if($_COOKIE['otp'] == $otp1){ echo "Your OTP is verified!"; dashboard() } else{ echo "You Entered a wrong OTP"; }; die(); } add_action('wp_ajax_nopriv_otp_verify','otp_verify'); add_action('wp_ajax_otp_verify','otp_verify');
//css (if required) .container{ height:400px; width:600px; background:; padding:50px 50px; margin:50px auto; } .fullrow{ width:100%; } .submit{ width:40%; margin-top:20px; }
POST COMMENTS