I have searched for this but all I can find is an answer if the site is wordpress.
I have 2 roles of users. Admin and SuperAdmin. In my database I have them as roles 1 & 2. I want to hide a menu item based on the role of the user.
LoginForm to check user input
$query = mysql_query("select * from members where password='$mypassword' AND username='$myusername' AND role='$role'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user'] = $myusername; // Initializing Session
$token = md5(uniqid());
$_SESSION['token'] = $token;
$_SESSION['role'] = $role;
$query = mysql_query("update token from members where username='$myusername' set token = '$token'", $connection);
Here is what I have after the member is logged in.
<?php
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true);
// User still logged
$role = $row['role'];
if ($_GET['role'] == '2') {
$showdiv = 'super';
}
else if ($_GET['role'] == '1') {
$showdiv = 'admin';
}
echo "<script type=\"text/javascript\">document.getElementById('".$showdiv."').style.display = 'block';</script>";
?>
Then I have this where the menus are. (Only the supernavbar is showing)
<div class="mainbar">
<div id="super">
<?php include("supernavbar.php"); ?>
</div>
<div id="admin">
<?php include("navbar.php"); ?>
</div>
</div> <!-- /.mainbar -->
I might have found the solution here (thanks to "related questions") Loading role-based navigation upon login
But my question on that, would I get the "role" from the login or on the 2nd page when they are logged in?