Jump to content

I need code that reads from the role database and displays the file according to it


Recommended Posts

Hi, I need code that reads from the roles database and then selects which file from these 3 which I want. For example, the user.php file would be loaded if the user has UName = user, Pass = 124, and Roles = User added to the database. But the admin.php and boss.php files would not appear to him.
Then only the user who would have it like UName = admin Pass = 125 and Roles = Admin would see the admin.php file, but he would not see the user.php and boss.php files. And of course the boss.php file would be seen by a user with UName = boss, Pass = 126 and Roles = Boss.
Please use only PDO!
I need to write this in this code somehow.

 

<?php
    session_start();

    if(!(isset($_SESSION['User'])))
    {
        header("Location: index.php");
        exit(0);
    }	  

?>
<!DOCTYPE html>
<html>
<body>
<?php 
include "config.php";
?>
<!--show for User-->
<?php include 'user.php';?>
<!--show for Admin-->
<?php include 'admin.php';?>
<!--show for Boss-->
<?php include 'boss.php';?>
</body>
</html>

 

 

Assign role to users

Have an access table to define which roles can access which files (As requested, all tables are accessible via PDO)

+-------------+             +---------------+                          +--------------+
|  user       |             |   role        |                          |  file        |
+-------------+             +---------------+                          +--------------+
| user_id     |      +------| role_id       |-+                    +---|  file_no     |
| username    |      |      | description   | |                    |   |  filename    |
| password    |      |      +---------------+ |                    |   +--------------+
| role_id     |>-----+                        |                    |
+-------------+                               |                    |
                                              |   +-------------+  |
                                              |   |  access     |  |
                                              |   +-------------+  |
                                              +--<|  role_id    |  |
                                                  |  file_no    |>-+
                                                  +-------------+

 

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.