News:

Wondering if this will always be free?  See why free is better.

Main Menu

Silly question, but what id_group is my admin?

Started by rcane, March 20, 2023, 05:02:37 PM

Previous topic - Next topic

rcane

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?

Doug Heffernan

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.


rcane

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.

Doug Heffernan

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.

rcane

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.


Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rcane

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. 

Kindred

$user_info[groups] is the array that you want to use.

you can use in_array to pull the individual group id
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rcane

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'.

rcane

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.

Diego Andrés

$user_info['is_guest']
$context['user']['is_guest']
$context['user']['is_logged']

SMF Tricks - Free & Premium Responsive Themes for SMF.

rcane

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.

Kindred

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
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rcane

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.

Advertisement: