// retrieve user data from database based on login credentials $user = getUserData($_POST['username'], $_POST['password']); // set menu_perms session variable for the user if ($user['role'] == 'admin') { $_SESSION['menu_perms'] = 'admin'; } else if ($user['role'] == 'moderator') { $_SESSION['menu_perms'] = 'moderator'; } else { $_SESSION['menu_perms'] = 'user'; }
// check menu_perms value to display appropriate menus if ($_SESSION['menu_perms'] == 'admin') { // display admin menus } else if ($_SESSION['menu_perms'] == 'moderator') { // display moderator menus } else { // display user menus }In this example, we check the value of the menu_perms session variable to determine which menus to display to the user. If the user is an admin, we display the admin menus. If they're a moderator, we display the moderator menus. Otherwise, we display the user menus. The package library used in this example is the PHP standard library, as the session variables used here are part of the native PHP session handling functions.