如何禁用/隐藏html页面中的控件给某些用户[关闭]

如何禁用/隐藏html页面中的控件给某些用户[关闭]

问题描述:

I am creating a small MIS with html and php with mysql database and there is a login function for the users and they have different user Levels.For example the manger's user level is 1. I want to create user grants for the system by disabling some controls such as buttons and tabs based on the user level. For example how can I disable this, for a user who has a user level of 1.

                          <li>
                          <a href="SearchProduct.php">Search</a>
                        </li>

Say for example your user is logged and you have his level saved in $_SESSION['level'] or in $data['level'] representing the row fetched from your database. In your PHP you could simply do

<?php
    if ($level > 1) // Only for users above lvl 1 (at least lvl 2)
    {
        echo '<li>
                  <a href="SearchProduct.php">Search</a>
              </li>
    }
?>

Now your search bar is only visible to users above level 1. Make sure you replace the $level variable by the actual level of the currently logged user (either from $_SESSION['level'] or from the result of a query)