How to assign different functions to different types of users?

0

I am creating a platform for students and teachers, and each one has different functions in their profile.
When they are registered, each one in my database is automatically assigned a 1 or a 2, depending on what type of user it is.

  

1 = Teacher
  2 = Student

And I'm creating a PHP file called Profile.php where I've been creating functions that both profiles occupy, but I've run into functions unique to teachers.

I thought about using a query similar to this one:

 if(DB::query('SELECT TipoUsuario FROM registroalumnos WHERE TipoUsuario = 1'))

Thank you.

    
asked by Antonio Alejos 13.08.2018 в 20:56
source

1 answer

0

If you want to differentiate users in order to assign them different levels of access you can create a column called "role" or "level" within your user table, each number will identify a different role.

Ex:

  

1 = Teacher   2 = Student

Already having this data you can obtain for a number of different options, but I recommend that when logging stores this ID in a session variable

$ _ SESSION ['level'];

During the execution of each script you can call this variable and you can use it to apply filters on the content that you show or the queries that you execute.

Example:

    <?php 
    $nivel=$_SESSION['id_usuario'];
    if($nivel=="1")
    {
    /////aqui puedes poner lo que quieras que solo este nivel ejecute
echo "Eres un maestro";
    }

    if($nivel=="2")
    {
    /////aqui puedes poner lo que quieras que solo este nivel ejecute
echo "Eres un Alumno";
    }
    ?>

Good luck, I hope I helped you.

    
answered by 14.08.2018 в 06:28