-
Notifications
You must be signed in to change notification settings - Fork 2
/
RegistrationOtp.php
162 lines (150 loc) · 4.55 KB
/
RegistrationOtp.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
include('include/main.php');
include('include/header.php');
?>
<style>
form, .content {
width: 40%;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
background: white;
border-radius: 0px 0px 10px 10px;
height:490px;
}
.input-group {
width: 80%;
margin: 10px 0px 10px 50px;
}
.input-group label {
display: block;
text-align: left;
margin: 3px;
}
.input-group input {
height: 30px;
width: 100%;
padding: 5px 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid gray;
}
.btn {
padding: 10px;
font-size: 15px;
color: white;
background: #5F9EA0;
border: none;
border-radius: 5px;
}
.error {
color: #a94442;
margin-left:5px;
}
.success {
color: #3c763d;
background: #dff0d8;
border: 1px solid #3c763d;
margin-bottom: 20px;
}
.input-group select
{
width:100%;
height:30px;
border-radius: 5px;
border: 1px solid gray;
}
</style>
<script>
function myFunction(){
// document.getElementById('verifyid').style.visibility = 'hidden';
// document.getElementById('otpid').style.visibility = 'hidden';
}
</script>
<body onload="myFunction()">
<form name="myForm" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="input-group" id ="emailid">
<label >Email<span class="error">* </span></label>
<input type="email" name="email" placeholder="Enter Email Here" >
</div>
<div class="input-group" id="otpid">
<input type="text" name="otp" placeholder="One Time Password">
</div>
<div id = "sendid" class="input-group">
<button class="btn" name="send" value ="check" style="float: left;" onClick = "myFunction()">Send</button>
</div>
<div class="input-group" id="verifyid">
<button class="btn" name="verify" style="float: left;">Verify</button>
</div>
</form>
</body>
<?php
require('comman/connect.php');
$success = "";
$error_message = "";
if(isset($_POST['send']))
{
$newEmail = $_POST['email'];
$res=mysqli_fetch_array($con->query("select Email from registration where Email='$newEmail'"));
if($res != null)
{
echo "<script>alert('Email Already exist');</script>";
echo"<script>window.location.href='SignIn.php';</script>";
}
else{
$allowedDomains = array('nitjsr.ac.in');
list($user, $domain) = explode('@', $_POST['email']);
if($allowedDomains[0] == $domain){
// if (checkdnsrr($domain, 'MX') && in_array($domain, $allowedDomains))
//{
$email = $_POST['email'];
$otp = rand(100000,999999);
$to = $_POST['email'];
$sub = "This is an otp verification";
$headers = "From:[email protected]";
$message = "Your one time OTP is ".$otp."";
if(mail($to,$sub,$message,$headers)){
$result = mysqli_query($con,"INSERT INTO otp_expiry(otp,is_expired,create_at,Email) VALUES ('" . $otp . "', 0, '" . date("Y-m-d H:i:s"). "','$email')");
$current_id = mysqli_insert_id($con);
echo "<script>alert('Email Sent');</script>";
?>
<script>
document.getElementById('emailid').style.visibility = 'hidden';
document.getElementById('sendid').style.visibility = 'hidden';
</script>
<?php }
else {
echo "<script>alert('Email Does Not Exists');</script>";
}
}
else{
$emailErr = "Please Use Institue Email Id Only";
echo "<script>alert('Use Institute Email ID');</script>";
}
}
}
if(isset($_POST['verify']))
{?>
<?php
$result = mysqli_query($con,"SELECT * FROM otp_expiry WHERE otp='" . $_POST["otp"] . "' AND is_expired!=1 AND NOW() <= DATE_ADD(create_at, INTERVAL 24 HOUR)");
$count = mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
$email = $row['Email'];
?>
<script>var name='<?php echo $email; ?>'</script>;
<?php
if(!empty($count)) {
$result = mysqli_query($con,"DELETE FROM `otp_expiry` WHERE otp = '" . $_POST["otp"] . "'");
$success = 2;
echo '<script language="javascript">
localStorage.setItem("Email",name);</script>';
echo '<script language="javascript">window.location.href="Registration.php";</script>';
} else {
$success = 1;
$error_message = "Invalid OTP!";
echo "<script>alert('Otp Incorrect');</script>";
}
}
?>
<?php
include("include/footerstrip.php");?>