-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateOtpAndSend.php
73 lines (42 loc) · 1.88 KB
/
GenerateOtpAndSend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
include 'config/DatabaseConfiguration.php';
$con = mysqli_connect($host,$username,$password,$database);
$json = file_get_contents('php://input');
$obj = json_decode($json,true);
$phone = $obj['phone'];
$user_id = $obj['user_id'];
$otp = rand(100000,999999);
date_default_timezone_set("Asia/Calcutta");
$DateTime = date("Y-m-d H:i:s");
$Sql_Query = "INSERT INTO `mobile_otp_verification` (`user_id`, `user_mobile`, `otp`,`date_time_of_generation`) VALUES ('$user_id', '$phone', '$otp', '$DateTime');";
if(mysqli_query($con,$Sql_Query)){
$MSG = 'OTP successfully added to database';
$json = json_encode($MSG);
//Sending OTP//////////////////////////
$sender ='XXXXXX';
$mob = $phone;
$auth='XXXXXXX';
$msg = urlencode("XXXXXXXXXXXX");
$url = 'XXXXXXXX'; // API URL
//function define
function SendSMS($hostUrl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $hostUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // change to 1 to verify cert
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
return $result;
}
//
$result=SendSMS($url); // call function that return response with code
echo $result;
////////////////////////////////////////
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>