1
braddk
Global variable for Xoops group?
  • 2003/8/6 22:41

  • braddk

  • Just popping in

  • Posts: 2

  • Since: 2003/7/22


Is there a global variable for groups in Xoops?

I have some content that I want to prevent users not within specific groups from looking at. ALthough WFSections or something like that is an option, to make URLs simpler, as well as more control, I would rather force authentication based upon a callable variable.

I am able to require that the user logs in to see static content, per the following thread.

I would think that it'd be an easy call to a global variable. I have found the following call in ./includes/common.php. Presumably this is an array:
Quote:
$xoopsUser->getGroups()


If this is the case, than i think the code would be something like this:
Quote:

global $xoopsUser;
foreach ($xoopsUser->getGroups() as $group) {
if (in_array(1, $group) //or whatever the groupid is
//display content
else
//redirect to user.php
}


What do you all think?

edit: I had in_array variables backwards.

2
ackbarr
Re: Global variable for Xoops group?

rather than calling $xoopsUser->getGroups() for each iteration of the for loop, I would store the group array into a local variable first. Other than that, the code should work fine.

3
braddk
Re: Global variable for Xoops groups?
  • 2003/8/7 21:58

  • braddk

  • Just popping in

  • Posts: 2

  • Since: 2003/7/22


ackbarr: makes sense.

I have implemented this, and just so it is documented in the forums so someone else can find this with a search, the code I used was the following:
Quote:

global $xoopsUser;
if(!empty($xoopsUser)) {
$group = $xoopsUser->getGroups();
if (in_array(1, $group)) { //or whatever the groupid is
echo "you are authorized to view this material";
}
else {
echo "you are not authorized to view this material";
}
}
else
echo "not logged in";

I found that if I did not include the if(!empty($xoopsUser)) test, than no content would be displayed at all if the user wasn't logged in.

4
Mithrandir
Re: Global variable for Xoops groups?

Right, the evul "Call to a member function..." error

5
bimmer528
Re: Global variable for Xoops groups?
  • 2003/10/19 6:42

  • bimmer528

  • Just popping in

  • Posts: 19

  • Since: 2002/9/19


How about more then 1 group? Or adding more Group id's to that code?

Login

Who's Online

225 user(s) are online (153 user(s) are browsing Support Forums)


Members: 0


Guests: 225


more...

Donat-O-Meter

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

Latest GitHub Commits