forked from durgesh-sahani/send-mobile-otp-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
84 lines (79 loc) · 2.88 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>Send SMS from PHP using textlocal</title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 class="text-center">Sending OTP SMS in PHP from localhost using textlocal</h1>
<hr>
<div class="row">
<div class="col-md-9 col-md-offset-2">
<?php
if(isset($_POST['sendopt'])) {
require('textlocal.class.php');
require('credential.php');
$textlocal = new Textlocal(false, false, API_KEY);
// You can access MOBILE from credential.php
// $numbers = array(MOBILE);
// Access enter mobile number in input box
$numbers = array($_POST['mobile']);
$sender = 'TXTLCL';
$otp = mt_rand(10000, 99999);
$message = "Hello " . $_POST['uname'] . " This is your OTP: " . $otp;
try {
$result = $textlocal->sendSms($numbers, $message, $sender);
setcookie('otp', $otp);
echo "OTP successfully send..";
} catch (Exception $e) {
die('Error: ' . $e->getMessage());
}
}
if(isset($_POST['verifyotp'])) {
$otp = $_POST['otp'];
if($_COOKIE['otp'] == $otp) {
echo "Congratulation, Your mobile is verified.";
} else {
echo "Please enter correct otp.";
}
}
?>
</div>
<div class="col-md-9 col-md-offset-2">
<form role="form" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-9 form-group">
<label for="uname">Name</label>
<input type="text" class="form-control" id="uname" name="uname" value="" maxlength="10" placeholder="Enter your name" required="">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<label for="mobile">Mobile</label>
<input type="text" class="form-control" id="mobile" name="mobile" value="" maxlength="10" placeholder="Enter valid mobile number" required="">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<button type="submit" name="sendopt" class="btn btn-lg btn-success btn-block">Send OTP</button>
</div>
</div>
</form>
<form method="POST" action="">
<div class="row">
<div class="col-sm-9 form-group">
<label for="otp">OTP</label>
<input type="text" class="form-control" id="otp" name="otp" placeholder="Enter OTP" maxlength="5" required="">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<button type="submit" name="verifyotp" class="btn btn-lg btn-info btn-block">Verify</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>