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