· 6 years ago · Mar 07, 2020, 04:46 AM
1//display send otp after 2 minutes
2$(document).ready(function() {
3 //http://navaneeth.me/simple-countdown-timer-using-javascript/#.XltbYHDhXIU
4 var timeoutHandle;
5function countdown(minutes) {
6 var seconds = 60;
7 var mins = minutes
8 function tick() {
9 var counter = document.getElementById("timer");
10 var current_minutes = mins-1
11 seconds--;
12 counter.innerHTML =
13 current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
14 if( seconds > 0 ) {
15 timeoutHandle=setTimeout(tick, 1000);
16 } else {
17
18 if(mins > 1){
19
20 // countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst
21 setTimeout(function () { countdown(mins - 1); }, 1000);
22
23 }
24 }
25 }
26 tick();
27}
28
29countdown(1);
30
31 setTimeout(function() {
32 $(".otplink").show();
33 $(".resendlink").hide();
34 }, 60000);
35});
36
37
38
39//resend OTP
40$(function() {
41 $('.otplink').click(function(event) {
42 event.preventDefault();
43
44 var number = $(this).attr("data-mobile");
45 var hash = $(this).attr("data-hash");
46
47 $.ajax({
48 type: 'POST',
49 url: 'ajax/resentOTP.php',
50 data: {number: number, hash: hash},
51 beforeSend: function() {
52 $(".message").html("<img src='assets/img/10.gif' alt='loading'> Please wait...");
53 $(".otplink").hide(0);
54 }
55 }).done(function(data) {
56 $(".otplink").show();
57 $(".message").html(data);
58 });
59 });
60});
61
62
63<h4 class="mt-4 text-right"><a disabled class="text-primary otplink" data-mobile="<?php echo $_SESSION['mobileNumber'];?>" data-hash="<?php echo $_SESSION['csrf'];?>" style="cursor: pointer;">Resend OTP</a></h4>
64
65
66
67<?php session_start();
68
69 //include db connection
70 include("../include/db.php");
71
72 //reterieve data from the FORM
73
74 $int = strip_tags(stripcslashes(stripslashes(htmlentities(mysqli_real_escape_string($con, $_POST['number'])))));
75 $token = strip_tags(stripcslashes(stripslashes(htmlentities(mysqli_real_escape_string($con, $_POST['hash'])))));
76 //$bot = strip_tags(stripcslashes(stripslashes(htmlentities(mysqli_real_escape_string($con, $_POST['bot'])))));
77 $token1 = $_SESSION['csrf'];
78
79 //check if token matches
80 if($token == $token1){}else{echo "<code style='background:lightpink;border-radius:10px;border:1px solid red;padding:5px;'><b>Error: </b> Direct access prohibited.</code>"; exit(); die();}
81
82 //check if the form is filled by the BOT; if yes redirect it to BOT page.
83
84
85
86 //check if mobile number is empty
87 if($int == ""){
88?>
89 <!-- error warning -->
90 <div class="my-2 alert alert-warning alert-dismissible fade show" role="alert">
91 <i data-feather="warning-triangle"></i> Please enter your mobile number.
92 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
93 <span aria-hidden="true">×</span>
94 </button>
95 </div>
96 <!-- end -->
97<?php
98
99 //if field is empty; stop the script and display above error message
100 exit();
101 }
102
103 //check if mobile number is integer
104 if (is_numeric($int)) {} else {
105?>
106
107 <!-- error warning -->
108 <div class="my-2 alert alert-warning alert-dismissible fade show" role="alert">
109 <i data-feather="warning-triangle"></i> Please enter mobile number in correct format.
110 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
111 <span aria-hidden="true">×</span>
112 </button>
113 </div>
114 <!-- end -->
115
116<?php
117 //stop the script
118 exit();
119 }
120
121 //check if mobile number length is less than 10 digits
122 $len = strlen($int); // Outputs: 12
123 if($len < 10){
124 echo '
125 <div class="my-2 alert alert-warning alert-dismissible fade show" role="alert">
126 <i data-feather="warning-triangle"></i> Your mobile number shall contain 10 digits.
127 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
128 <span aria-hidden="true">×</span>
129 </button>
130 </div>
131 ';
132 exit();
133 }
134
135
136 //send OTP to the mobile number
137
138 //Your authentication key
139 $authKey = "14493AYNsvW2tXKjE5dedeea8";
140
141 //Multiple mobiles numbers separated by comma
142 $mobileNumber = $int;
143
144 //Sender ID,While using route4 sender id should be 6 characters long.
145 $senderId = "VMGOOD";
146
147 //OTP
148 $OTP = $_SESSION['OTP'];
149
150 //Your message to send, Add URL encoding here.
151 $message = urlencode("OTP Code:" . " " . $OTP . " " . "\n\nPlease do not share this OTP code with anyone. \n\n ~ Team 2GoodStore");
152
153 //Define route
154 $route = "4";
155
156 //response
157 $response= "json";
158
159 //Prepare you post parameters
160 $postData = array(
161 'authkey' => $authKey,
162 'mobiles' => $mobileNumber,
163 'message' => $message,
164 'sender' => $senderId,
165 'route' => $route,
166 'response' => $response
167 );
168
169 //API URL
170 $url="http://sms.whybulksms.com/api/sendhttp.php";
171
172 // init the resource
173 $ch = curl_init();
174 curl_setopt_array($ch, array(
175 CURLOPT_URL => $url,
176 CURLOPT_RETURNTRANSFER => true,
177 CURLOPT_POST => true,
178 CURLOPT_POSTFIELDS => $postData
179 //,CURLOPT_FOLLOWLOCATION => true
180 ));
181
182
183 //Ignore SSL certificate verification
184 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
185 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
186
187
188 //get response
189 $output = curl_exec($ch);
190
191 //Print error if any
192 if(curl_errno($ch))
193 {
194 echo 'error:' . curl_error($ch);
195 }
196
197 curl_close($ch);
198
199 $values = json_decode($output, true);
200
201 //echo $output;
202
203 $isSuccess = $values["type"];
204
205 if($isSuccess == "success"){
206 //redirect the user to verify the OTP
207 $_SESSION['mobileNumber'] = $mobileNumber;
208 $_SESSION['OTP'] = $OTP;
209 echo '
210 <div class="my-2 alert alert-success alert-dismissible fade show" role="alert">
211 <i data-feather="info"></i> OTP sent to your mobile number successfully.
212 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
213 <span aria-hidden="true">×</span>
214 </button>
215 </div>
216 ';
217 }else{
218 //display an error message.
219 echo '
220 <div class="my-2 alert alert-warning alert-dismissible fade show" role="alert">
221 <i data-feather="warning-triangle"></i> An unknown error occurred. Please try again after refreshing the page.
222 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
223 <span aria-hidden="true">×</span>
224 </button>
225 </div>
226 ';
227 exit();
228 }
229
230?>