-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginEx.php
66 lines (49 loc) · 2.06 KB
/
loginEx.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
<?php
session_start();
include "db_conn.php";
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST["username"];
$password = $_POST["password"];
$conn = mysqli_connect('localhost', 'root', '', 'studybuddy');
if ($conn===false) {
echo "Die";
} else {
// $sql = "SELECT `state` FROM `account` WHERE username = '$username' AND password = '$password'";
// $result = mysqli_query($conn, $sql);
// $row = mysqli_fetch_array($result);
// $passwordEn = password_needs_rehash($password, PASSWORD_DEFAULT);
$sql2 = "SELECT * FROM `account` WHERE username = '$username' AND password = '$password'";
$result2 = mysqli_query($conn, $sql2);
if ($result2 && mysqli_num_rows($result2) > 0) {
$row2 = mysqli_fetch_array($result2);
$role = $row2["role"];
$state = $row2["state"];
// Get the current time in the Philippines
date_default_timezone_set('Asia/Manila');
$currentDateTime = date('Y-m-d H:i:s');
$date = date('Y-m-d', strtotime($currentDateTime));
$time = date('H:i:s', strtotime($currentDateTime));
$sql3 = "INSERT INTO `log`(`username`, `event`, `date`, `time`)
VALUES ('$username','logged in', '$date', '$time')";
$result3 = mysqli_query($conn, $sql3);
if ($role === "admin") {
$_SESSION['userOnline'] = $username;
echo "Admin";
} else if ($role === "user") {
if ($state == "verified") {
$_SESSION['userOnline'] = $username;
echo "User";
} else if ($state == "not-verified"){
echo "Not-Verified";
} else if ($state == "deactivated"){
echo "Deactivated";
}
} else {
echo "Failed";
}
} else {
echo "Failed";
}
}
}
?>