Hello everyone, im new to these forums and i dont really know much but this looks like a really good place to ask some php questions. To begin im not really that good with php but im good with html/css. I have started a new website where people can add blogs and admins can make updates on the main page using a simple "INSERT $fields into a database".
I have set up a userlevel field on the database containing the users and the numbers are "1" which is the standard user and is given on sign up. "5" which is a moderator and "9" which is an administrator".
I have this peice of code defining this in constants.php
define("ADMIN_NAME", "Admin");
define("MODERATOR_NAME", "Moderator");
define("GUEST_NAME", "Guest");
define("ADMIN_LEVEL", 9);
define("MODERATOR_LEVEL", 5);
define("USER_LEVEL", 1);
define("GUEST_LEVEL", 0);
and in another file called sessions.php i have made a function for admins and moderators like this :
/**
isAdmin - Returns true if currently logged in user is
an administrator, false otherwise.
*/
function isAdmin(){
return ($this->userlevel == MODERATOR_LEVEL ||
$this->username == ADMIN_NAME);
}
/* isModerator - Returns true if currently logged in user is
an moderator, false otherwise. */
function isModerator(){
return ($this->userlevel == MODERATOR_LEVEL ||
$this->username == MODERATOR_NAME);
}
Ok that works because if my level is 9 and i put this piece of code in any page :
if($session->isAdmin()){
code here
}
and it works the same with $session->isModerator()) when my level is 5.
BUT heres the problem, if i put $session->isModerator and place links, i can only see if my level is 5, how can i fix this so if my level is 9 and i can see isModerator functions and isAdmin but moderators can only see their functions. Its tricky to explain.
For example i could have
echo "You are logged in as $user";
if($session->isModerator()){
echo " (<a href=\"#\">Moderator Base</a>)";
}
if($session->isAdmin()){
echo " (<a href=\"#\">Admin Panel</a>)"
}
So if your a user you just see "Your logged in as $user", if your a moderator you see that and the "Moderator Base" link and if your an admin you would see the "Your logged in as $user" the "Moderator Base" and the "Admin Panel" link ??
Its tricky to explain but if anyone can help me i would really appreciate it. Thank you for taking time out to read this.