-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.php
More file actions
107 lines (88 loc) · 3.67 KB
/
Copy pathlog.php
File metadata and controls
107 lines (88 loc) · 3.67 KB
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
<?php
include 'connect/config.php';
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username = '$username'";
$result = $conn->query($query);
if ($result->num_rows == 1) {
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['user_id'];
$id = $user['user_id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
$_SESSION['college_id'] = $user['college_id'];
$c_id = $user['college_id'];
$_SESSION['avt'] = $user['avt'];
if ($user['role'] == 'admin') {
header("Location: admin/admin.php");
} elseif ($user['role'] == 'staff') {
$query = "SELECT u.*, s.*, c.*
FROM users u
INNER JOIN staff s ON u.user_id = s.user_id
INNER JOIN staff_subjects_classes c ON s.staff_id = c.staff_id
WHERE u.college_id = '$c_id' AND u.user_id = '$id'";
$result = $conn->query($query);
if ($user = mysqli_fetch_assoc($result)) {
$_SESSION["staff_id"] = $user["staff_id"];
$_SESSION["username"] = $user["username"];
$_SESSION["subject_id"] = $user["subject_id"];
$_SESSION["class_id"] = $user["class_id"];
header("Location: staff/staff.php");
exit();
}
} else {
$query = "SELECT u.*, s.*
FROM users u
INNER JOIN students s ON u.user_id = s.user_id
WHERE u.college_id = '$c_id' AND u.user_id = '$id'";
$result = $conn->query($query);
if ($user = mysqli_fetch_assoc($result)) {
$_SESSION["student_id"] = $user['student_id'];
$_SESSION['roll_number'] = $user['roll_number'];
$_SESSION['class_id'] = $user['class_id'];
header("Location: student/stud.php");
}
}
exit();
} else {
$error_message = "Invalid password.";
}
}
$error_message = "No such user found .";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - Academic Hub</title>
<link rel="shortcut icon" href="img/favicon.png" type="image/x-icon" />
<link rel="stylesheet" href="css/log.css">
</head>
<body>
<div class="login-container">
<div class="login-box">
<h1>Login to Academic Hub</h1>
<?php if (isset($error_message)): ?>
<p style="color:red;"><?php echo $error_message; ?></p>
<?php endif; ?>
<form method="POST">
<div class="input-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username" required>
</div>
<div class="input-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
</div>
<button type="submit" name="submit">Login</button>
<p>Don't have an account? <a href="register.php">Sign up here</a></p>
</form>
</div>
</div>
</body>
</html>