0

I have a project in which i have two roles :
Student
Teacher

I have already created a login page but i cant figure out how to redirect them to different pages according to their Roles...

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by broj1
0

Hi,

Try adding a new column and name it role.. and then it is all up to you how are you going to assign values to sort between teacher and student.

For example, if we are to give an integer 7 for the role of teacher and a value of 1 for student, then we can easily sort their privileges and page access..

Sample query..

$query = "SELECT * FROM TableName WHERE title='".$title."' ";
## pull out the result as $row


## then check for the role

if($row['role']== 7){
## label this member as teacher. You can store this in session
$isTeacher = true;


## this user must be a teacher
## redirect this member to the teachers only page
}
else{
$isStudent = true;

## this member must student
## redirect this member to students only page

}

You can also expand the members privs, by adding more role valu e.g. 8, 9, or better yet make a triple digits like 100 for students, 700 for teachers, 900 for supervisors, and others.

Notice I define $isTeacher = true;?, you can put this in session, so that it is a lot easier for them to browse across the site without having to re-validate their role..

Example

if($isTeacher){
## if true then this member will only see menu or pages applicable to teachers only

}

Edited by veedeoo: n/a

0

It is a good idea to plan ahead as much as possible. The higher the access rights are the higher the role value. As veedeoo suggested it pays if you use values that have enough free values between them so you can always add a new role which fits between two existing roles (ie. 200 for students with more privileges, 600 for teachers -trainees or 800 for administrators who have less rights than supervisors).

You can store the access rights based on the role in a session variable at loging time:

$_SESSION['access_level'] = 700;

and then check it on every page:

if(!isset($_SESSION['access_level']) or $_SESSION['access_level'] < 700) {

    log_this_guy_out();
}

// code for successfully logged in users
// ...
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.