-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotpphp.php
37 lines (30 loc) · 1.05 KB
/
otpphp.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
<?php
include("./php/database.php");
$response = ""; // Initialize the response variable
if($_SERVER["REQUEST_METHOD"] == "POST") {
$otp = $_POST['otp'];
if(isset($_SESSION['user'])) {
$username = $_SESSION['user'];
$sql = "SELECT * FROM login WHERE Email='$username' AND Otp='$otp'";
$result = $conn->query($sql);
if($result->num_rows > 0) {
// Valid OTP, update the database and notify success
$sql = "UPDATE login SET Otp='0' WHERE Email='$username' AND Otp='$otp'";
$result = $conn->query($sql);
if($result) {
$response = 'OTP verified successfully';
} else {
$response = 'Unable to update OTP';
}
} else {
// Invalid OTP
$response = 'Invalid OTP';
}
} else {
// Invalid session or user not set
$response = 'Invalid session or user';
}
}
// Send the response back
echo $response;
?>