-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinclude.php
61 lines (53 loc) · 1.28 KB
/
include.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
<?php
/*
isAdmin
Purpose:
Returns whether currently logged in user is an admin
Parameters:
$id, the userId of the currently logged in user
Returns:
whether the user is an administrator
*/
function isAdmin($id)
{
// Open database connection
$conn = mysqli_connect(DB_HOST_NAME, DB_USER, DB_PASS, DB_NAME);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT a.*
FROM Administrators a
WHERE a.userId = '$id';";
// perform database query
$result = mysqli_query($conn, $query);
mysqli_close($conn);
return (mysqli_num_rows($result) > 0);
}
function isBanned($id)
{
// Open database connection
$conn = mysqli_connect(DB_HOST_NAME, DB_USER, DB_PASS, DB_NAME);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT isBanned
FROM Users u
WHERE userId = '$id' AND isBanned = true;";
// perform database query
$result = mysqli_query($conn, $query);
mysqli_close($conn);
return (mysqli_num_rows($result) != 0);
}
function checkUserSession() {
if(!isset($_SESSION['login_user'])) {
header('Location: '.SIDEBAR_LOGIN);
} else if (isBanned($_SESSION['login_user'])) {
echo "<script>
alert('You have been banned!');
window.location.href='/cs372/logout.php';
</script>";
exit();
}
}