Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: rcane on March 20, 2023, 05:02:37 PM

Title: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 05:02:37 PM
In my current forum, it's 1.

In a quickly built, temp, forum it seems to show id_group 1 in both members table as well as defined as 1 = admin in membergroups table.

Yet, when I try to put a custom button on the index-template page, below the bit that says "custom banners...go here" it won't work unless I say that I'm NOT in group 1.


if (in_array(1, $user_info['groups'])) {
echo '<a href="link>CLICK</a>' ;
}


However it only works if I change it to:   if (!in_array(1, $user_info['groups'])).


Ideas as to why?
Title: Re: Silly question, but what id_group is my admin?
Post by: Doug Heffernan on March 20, 2023, 05:11:47 PM
if (in_array(1, $user_info['groups']))
echo '<a href="link>CLICK</a>';


This code should show it to admins only. is $user_info declared as global?

Anyways, I think it is better to use $context['user']['is_admin'] instead. Make sure to declare $context as global if you are using the code in a place where that is not the case.

Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 05:15:12 PM
Quote from: Doug Heffernan on March 20, 2023, 05:11:47 PMif (in_array(1, $user_info['groups']))
echo '<a href="link>CLICK</a>';


This code should show it to admins only. is $user_info declared as global?

Anyways, I think it is better to use $context['user']['is_admin'] instead. Make sure to declare $context as global if you are using the code in a place where that is not the case.

I normally include ssi.php if the page is of my own design to permit this to work. 

I'm using it in the default theme's index-template.php.

In fact, I use that type of language (except I use other groups to restrict pages), and I've never declared $context before.  Haven't had to so far. 

$user_info['groups'] is a part of ssi.
Title: Re: Silly question, but what id_group is my admin?
Post by: Doug Heffernan on March 20, 2023, 05:23:49 PM
Quote from: rcane on March 20, 2023, 05:15:12 PMI've never declared $context before.  Haven't had to so far.

It is declaired within the smf functions, that is why. I mentioned it as a reminder for just in case you were using your own function or using your code in an external file or something along those lines.
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 06:20:02 PM
I un-installed and put a clean 2.0.19 in the root of the domain.

I can't make that code work as it does on other installations.  It's like ssi isn't picking it up.

I tried using the core theme with no luck either.

Title: Re: Silly question, but what id_group is my admin?
Post by: Kindred on March 20, 2023, 06:49:28 PM
Why not use is_admin?
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 06:56:52 PM
Quote from: Kindred on March 20, 2023, 06:49:28 PMWhy not use is_admin?

Because I was using different user groups to filter out different membergroups from seeing the content--just kept the convention going.

Regardless, it doesn't work for id_group 0 either, and I presume that any other sub-groups I make won't work either.  I can understand me fouling up a personal page, perhaps not including ssi properly, but this is in the index template. 
Title: Re: Silly question, but what id_group is my admin?
Post by: Kindred on March 20, 2023, 07:05:10 PM
$user_info[groups] is the array that you want to use.

you can use in_array to pull the individual group id
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 07:08:51 PM
Quote from: Kindred on March 20, 2023, 07:05:10 PM$user_info[groups] is the array that you want to use.

you can use in_array to pull the individual group id

Yes, that's the code example I started with above.  I've used it too many times to count.

FWIW, if(is_admin) does work, though that doesn't help with membergroups.


AND, if I do:   (!in_array(1, $user_info[groups]))   it will work.   But, again, I know the group for admin is '1'.
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 07:16:00 PM
Kindred, since i need this up tonight (it comes down in 3 days), what's the syntax to test if someone is either a guest or not logged in--to render a few items not visible on the login screen?

That's why I use the in_array.

I can make it work since is_admin works.
Title: Re: Silly question, but what id_group is my admin?
Post by: Diego Andrés on March 20, 2023, 07:43:16 PM
$user_info['is_guest']
$context['user']['is_guest']
$context['user']['is_logged']
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 08:33:13 PM
Quote from: Diego Andrés on March 20, 2023, 07:43:16 PM$user_info['is_guest']
$context['user']['is_guest']
$context['user']['is_logged']

Yes.  Those are not working.
Title: Re: Silly question, but what id_group is my admin?
Post by: Kindred on March 20, 2023, 09:56:01 PM
If those are not working,  then you have something very very wrong.
Those are core settings in the array

BTW  $user_info['groups']

You need the quotes
Title: Re: Silly question, but what id_group is my admin?
Post by: rcane on March 20, 2023, 10:28:53 PM
Quote from: Kindred on March 20, 2023, 09:56:01 PMIf those are not working,  then you have something very very wrong.
Those are core settings in the array

BTW  $user_info['groups']

You need the quotes

I think it's all fixed.

There is a feature in my cPanel called mod security.  It was interfering with the install of themes (and I suspect the SMF to some degree). 

For some reason my host keeps flagging my IP and blocking me--tripping this mod security to fill me with 403 errors and such. 

I have turned it off until i get installs and setup done; then I'll decide if it needs to be on.  Have to read up on it.