1
miscade
How to show things only if the user is admin, registered or webmaster?
  • 2005/3/23 15:19

  • miscade

  • Just popping in

  • Posts: 18

  • Since: 2005/2/18


Hi guys,

I want to show something, say a button, or execute code only if the user has specific level, like being the webmaster.

how/where can I check this?

Any example?

________________
Miscade

2
bitkid
Re: How to show things only if the user is admin, registered or webmaster?
  • 2005/3/23 15:28

  • bitkid

  • Just popping in

  • Posts: 4

  • Since: 2003/9/12


Put it into a block that is only visible by webmasters.

3
ackbarr
Re: How to show things only if the user is admin, registered or webmaster?

Take a look at my response to this guy's question

4
miscade
Re: How to show things only if the user is admin, registered or webmaster?
  • 2005/3/23 17:18

  • miscade

  • Just popping in

  • Posts: 18

  • Since: 2005/2/18


Quote:

ackbarr wrote:
Take a look at my response to this guy's question


which included the following

Quote:

$groups = $xoopsUser->getGroups();

if (in_array(XOOPS_GROUP_ADMIN, $groups)) {
//User is in the administrators group
}



is fine for me.

Just one problem driving me crazy!

the line $groups = $xoopsUser->getGroups(); seems to make the page not work properly. The header and footer are no longer displayed....


If I comment out this line, the page (exept the code within the 'if') shows up correctly....

current includes are
include("../mainfile.php");
include("../header.php");

Any idea? Hints for digging it out?

Thanks.
______________
Miscade

5
ackbarr
Re: How to show things only if the user is admin, registered or webmaster?

the $xoopsUser variable only exists when a user is logged in. so if this page may be accessed by anonymous users you'll either need to check that the user logged in first, or you'll need to modify the code like so:
$groups = ($xoopsUser $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS));

if (
in_array(XOOPS_GROUP_ADMIN$groups)) {
  
//User is in the administrators group
}

6
miscade
Re: How to show things only if the user is admin, registered or webmaster?
  • 2005/3/23 17:49

  • miscade

  • Just popping in

  • Posts: 18

  • Since: 2005/2/18


G R E A T !

Works!
Thanks.
_________________
Miscade

7
Dave_L
Re: How to show things only if the user is admin, registered or webmaster?
  • 2005/3/23 19:42

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Also, make sure the block isn't cached. (Set "Cache lifetime" to "No Cache".)

Login

Who's Online

72 user(s) are online (29 user(s) are browsing Support Forums)


Members: 0


Guests: 72


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits