Providing various web users (administrators, clients) with various types of menus for creating a new account

I have a site with two access levels, Administrator and Client. When creating a new account, I want the administrator to see the possibility of creating another administrator or client. I want the client to see only the client option. I am using PHP. Here is what I tried:

 <?php
 foreach ($types as $type) {
    if (!isset($_SESSION['user_id'])) { //Anyone on the web can see
        echo "<option value=\"" . $type['Customer'] . "\">". $type['Customer'] . "</option>\n";
    }
    else 
    {
        if ($is_admin) { //Only admin can see this option
            echo "<option value=\"" . $type['user_type_id']. "\">" . $type['type_name'] . "</option>\n";
        }

    //Only customer can see
        echo "<option value=\"" . $type['Customer']. "\">" . $type['Customer'] ." </option>\n";
    }
}
?>

This is not the fulfillment of what I intended. If anyone has a suggestion that I could try, that would be great. Let me know if you want any of my other codes to understand the logic better.

+4
source share
1 answer

, , . , "else" .

  <?php
 foreach ($types as $type) {
    if (!isset($_SESSION['user_id'])) { //Anyone on the web can see
        echo "<option value=\"" . $type['Customer'] . "\">". $type['Customer'] . "</option>\n";
    }
    else 
    {
        if ($is_admin) { //Only admin can see this option
            echo "<option value=\"" . $type['user_type_id']. "\">" . $type['type_name'] . "</option>\n";
        } else { // <-- here

    //Only customer can see
        echo "<option value=\"" . $type['Customer']. "\">" . $type['Customer'] ." </option>\n";
       }
    }
}
?>
+3

Source: https://habr.com/ru/post/1617840/


All Articles