) I'm working on a login system that has 3 users(Admin, Teacher and Student) all of these users will have their own functions and interface. I would like to have one login for all these users together if this is possible i'm not sure.
Im my database there is a row Role('Admin','Teacher','Student') i want the login direct based on the "role" so the admin will be redirect to the admin homepage, the teacher to the teacher homepage and the student to the student homepage. The admin pages can only be viewed by the admin the teacher pages by the teacher and the student pages only by the students. You probably get what I mean.
Question:: How can i make the login so that it will check if it is a admin/teacher/student? and when they are logged in how can i make the specific homepage for that user vieuwable only by that type of user?
<?php
session_start();
$mysqli=new MySQLi("localhost", "root", "", "hws");
$role="";
$username=filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password=filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
if($query=$mysqli->prepare("SELECT `role` FROM members WHERE username=? AND password=?"))
{
$query->bind_param("ss", $username, $password);
$query->execute();
$query->bind_result($role);
$query->fetch();
}
else
{
echo "Errors in the Query. ".$mysqli->error;
die();
}
if($role!="")
{
$_SESSION['ingelogt']=$username;
$_SESSION['user_role']=$role;
$location="$role.php"; // If role is admin this will be admin.php, if student this will be student.php and more.
header("location: $location"); // Redirect to the respective pages.
}
else
{
echo "Invalid password, username combination";
}
?>
and for the userpage a example
<?php
session_start()
if(!isset($_SESSION['ingelogt']))
{
header("location: index.php"); // The user is not logged in. Redirect him to the login page.
}
$page_role="leerling"; // This must be admin for admin.php and student for student.php and similar
$role=$_SESSION['user_role'];
if($role!=$page_role) // If student come to admin page by mistake or admin to student and similar
{
echo "You are not supposed to be here.";
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/fontello.css">
</head>
<body>
<div class="siteContainer">
<div class="navLeft">
<a href="overzicht.php">
<img src="../../img/logo.png" alt="HWSysteem" class="mainLogo">
</a>
</div>
</div>
</body>
</html>