Check group

Discussion forum for MOD Writers regarding MOD Development.
Locked
Mitch1990
Registered User
Posts: 43
Joined: Mon Mar 22, 2010 4:42 pm
Name: Mitch

Check group

Post by Mitch1990 » Wed Mar 24, 2010 6:54 pm

Hello.

I have a few groups.
I have a own new page and i want to check if the visitor is logged in and if he is in the group "Members"

How can i do this?
Thanks.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51785
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Check group

Post by Brf » Wed Mar 24, 2010 6:58 pm

Code: Select all

if (group_memberships(77,$user->data['user_id'],true)) 
Where 77 is the group_id of that group.

That function is in includes/functions_user.php, so you would have to include that.

Mitch1990
Registered User
Posts: 43
Joined: Mon Mar 22, 2010 4:42 pm
Name: Mitch

Re: Check group

Post by Mitch1990 » Wed Mar 24, 2010 9:14 pm

Fatal error: Call to undefined function group_memberships()

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51785
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Check group

Post by Brf » Wed Mar 24, 2010 9:18 pm

Brf wrote: That function is in includes/functions_user.php, so you would have to include that.

Mitch1990
Registered User
Posts: 43
Joined: Mon Mar 22, 2010 4:42 pm
Name: Mitch

Re: Check group

Post by Mitch1990 » Wed Mar 24, 2010 9:44 pm

Brf wrote:
Brf wrote: That function is in includes/functions_user.php, so you would have to include that.
yea sorry,

Got a other error
Fatal error: Cannot redeclare deregister_globals()

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: Check group

Post by igorw » Wed Mar 24, 2010 10:19 pm

You are including common.php twice.
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

Mitch1990
Registered User
Posts: 43
Joined: Mon Mar 22, 2010 4:42 pm
Name: Mitch

Re: Check group

Post by Mitch1990 » Thu Mar 25, 2010 7:51 am

Ok thanks.

is this code:
if (group_memberships(8,$user->data['user_id'],true)){

}

Also in HTML ?

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check group

Post by Comkid » Thu Mar 25, 2010 9:36 am

Oh do this then:

OPEN: includes/functions.php

FIND:

Code: Select all

    // application/xhtml+xml not used because of IE
    header('Content-type: text/html; charset=UTF-8');  
ADD BEFORE:

Code: Select all

    // Check what group a user is in
    if ( !function_exists('group_memberships') )
    {
        include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
    }

    $groups = group_memberships(false,$user->data['user_id']);
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true
        ));
    }  
Then in the HTML you can use

Code: Select all

<!-- IF GROUP_ID == X AND S_USER_LOGGED_IN -->
Replace X with the group_id
I ist Comkid :P

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51785
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Check group

Post by Brf » Thu Mar 25, 2010 11:03 am

Comkid wrote: Then in the HTML you can use

Code: Select all

<!-- IF GROUP_ID == X AND S_USER_LOGGED_IN -->
Replace X with the group_id
No.

You would use

Code: Select all

<!-- IF S_GROUP_ID_X -->

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check group

Post by Comkid » Fri Mar 26, 2010 5:23 am

You forgot the S_USER_LOGGED_IN, he asked if they are in a group and is logged in ;)
I ist Comkid :P

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51785
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Check group

Post by Brf » Fri Mar 26, 2010 11:04 am

If you are not logged in, then you are only a member of the Guest usergroup. Therefore your check of another group would always be false. So checking if logged-in is redundant.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Check group

Post by RMcGirr83 » Fri Mar 26, 2010 12:26 pm

Comkid wrote:Oh do this then:

OPEN: includes/functions.php

FIND:

Code: Select all

    // application/xhtml+xml not used because of IE
    header('Content-type: text/html; charset=UTF-8');  
ADD BEFORE:

Code: Select all

    // Check what group a user is in
    if ( !function_exists('group_memberships') )
    {
        include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
    }

    $groups = group_memberships(false,$user->data['user_id']);
    foreach ($groups as $grouprec)
    {
        $template->assign_vars(array(
            'S_GROUP_' . $grouprec['group_id'] => true
        ));
    }  
Then in the HTML you can use

Code: Select all

<!-- IF GROUP_ID == X AND S_USER_LOGGED_IN -->
Replace X with the group_id

Hmmm, would have been nice if you had given credit where credit is due.

http://www.rmcgirr83.org/viewtopic.php?f=5&t=91 :roll:
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check group

Post by Comkid » Sat Mar 27, 2010 2:27 am

Sorry, I found it on Startrek Guide with no links ;)
I ist Comkid :P

Mitch1990
Registered User
Posts: 43
Joined: Mon Mar 22, 2010 4:42 pm
Name: Mitch

Re: Check group

Post by Mitch1990 » Fri Apr 02, 2010 9:04 pm

Brf wrote:

Code: Select all

if (group_memberships(77,$user->data['user_id'],true)) 
Where 77 is the group_id of that group.

That function is in includes/functions_user.php, so you would have to include that.
Now I got the error :

Fatal error: Cannot redeclare user_get_id_name() (previously declared in includes/functions_user.php:27) in includes/functions_user.php on line 82

what to do? :(
page:
server.php

Code: Select all

<?php
  require "lgsl_files/lgsl_config.php";

  include('includes/functions_user.php');
if (group_memberships(5,$user->data['user_id'],true)){
    define("LGSL_ADMIN", "1");
    require "lgsl_files/lgsl_admin.php";
 }else{
  	echo '
<br>
<center>Your not an admin.<br></center>
<br>';
  }

?>

User avatar
imkingdavid
Former Team Member
Posts: 2667
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Check group

Post by imkingdavid » Sat Apr 03, 2010 1:08 pm

If you're trying to see if they are an admin, wouldn't it be easier to use the $auth class?
Something like...

Code: Select all

if($auth->acl_get('a_'))
{
//user is admin
}
else
{
//user is NOT admin
} 
Because users outside of group 5 can potentially be given admin permissions but your script would not show it.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Locked

Return to “[3.0.x] MOD Writers Discussion”