I see my answer was givin' a bit to fast and didnt think he was asking for a specific user loaded by uid :)
But just wanted to point out that the roles exists within the user object.
Whether you assign a user any role or not, there is a role always assigned for a registered user.
Use the following code to check what's the role of a user possessed?
print_R($user->roles);
Yes, $user->roles is an array.
Now, when you get a clear idea of roles, just compare those roles in your code!
:) Beautifulmind
Can I use the following code to show an audio player?
<?php
global $user;
if ($user->role[4]) {
echo "I'll show the player now";
}
?>
On my site, I have unregistered users, and three other user roles that have different permissions each. I want only roles 2 & 4 to be able to access this audio player. Can I do this in a safe manner that it will always work?
Thanks
Navs
Comments
<?phpglobal $user;if
user_load
Hi Iumentum,
Wich Drupal do you have installed? I give you a short intro in Drupal 5.x. You load the user object via the user_load.
Lets suppose you want the role of the user on his user account.
first you make a user.-profile.tpl.php there are some examples around how to do this.
load the user via the first argument "user/uid"
For a node it will work like this
Print only if a user has a certain role:
get the id´s of the rolles via print_r($node_owner->roles);
Now you can start:
So i hope this will help you.
Cheers from Cologne
Dirk
I see my answer was givin' a
I see my answer was givin' a bit to fast and didnt think he was asking for a specific user loaded by uid :)
But just wanted to point out that the roles exists within the user object.
*_*
Whether you assign a user any role or not, there is a role always assigned for a registered user.
Use the following code to check what's the role of a user possessed?
Yes,
$user->rolesis an array.Now, when you get a clear idea of roles, just compare those roles in your code!
:)
Beautifulmind
Regards.
🪷 Beautifulmind
check permissions, not roles
I don't know what you want to achieve by checking the role, but in most cases, it makes more sense to check a permission than to check a role.
Can I use the following code
Can I use the following code to show an audio player?
On my site, I have unregistered users, and three other user roles that have different permissions each. I want only roles 2 & 4 to be able to access this audio player. Can I do this in a safe manner that it will always work?
Thanks
Navs
*_*
You should use in_array() of php.
Regards.
:)
Beautifulmind
Regards.
🪷 Beautifulmind
Can you please give me the
Can you please give me the syntax for using in_array(). I don't know if this is correct, please let me know:
Let me know if the syntax is correct for checking if a user with role "trader" is logged in?
Thanks
Navs
*_*
Yes it is.
But I think its
$user->rolesand not$user->roleCheck it.
:)
Beautifulmind
Regards.
🪷 Beautifulmind