-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess.php
More file actions
58 lines (49 loc) · 1.84 KB
/
Copy pathaccess.php
File metadata and controls
58 lines (49 loc) · 1.84 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
<?php
//When the file included all the variables and functions are available in the file.
include_once('db-connect.php');
//Get the user ID and password from the login form
$myid = $_POST['myid'];
$mypassword = $_POST['mypassword'];
// Secure the user ID and password from SQL injection
$myid = stripslashes($myid);
$mypassword = stripslashes($mypassword);
$myid = mysqli_real_escape_string($link, $myid);
$mypassword = mysqli_real_escape_string($link, $mypassword);
// Store the user ID in a session variable
session_start();
$_SESSION['login_id'] = $myid;
//sql query to select the user type(admin,teacher,parent) from the users table
$sql = "SELECT usertype FROM users WHERE userid='$myid' and password='$mypassword'";
//RUN THE QUERY and store the result in a variable
$result = mysqli_query($link, $sql);
// Count the number of rows in the result
$count = mysqli_num_rows($result);
// Fetch the user type from the result
$type = mysqli_fetch_array($result);
$control = $type['usertype'];
// Check if the count is not 1 or the user type is not set
if ($count != 1 || !isset($control)) {
// Redirect to the login page with a login error
header("Location:../index.php?login=false");
} else {
// Switch based on the user type
switch ($control) {
case "admin":
// Redirect to the admin module
header("Location:../users/admin");
break;
case "teacher":
// Redirect to the teacher module
header("Location:../users/teacher");
break;
case "parent":
// Redirect to the parent module
header("Location:../users/parent");
break;
default:
// If the user type doesn't match any case, redirect to the login page with a login error
header("Location:../index.php?login=false");
break;
}
}
?>