I added this code to parts of my site:
if ($context['user']['is_admin'])
{
echo '
<div>
Some other stuff here that you want to protect.
</div>';
}
and the only user command I know is ['is_admin'] how can find out what the others are for registered members, mods, etc.?
I don't get what your trying to do.. what are you trying to do?
Trying to restrict certain content from guests. Now the only group access I know is the ['is_admin'] I don't know what the others are for just regular members, mods, and any other groups I have.
http://docs.simplemachines.org/index.php?topic=789.msg1688#post_restrict
thats where i got the coding from.
Welcome to the world of PHP. :P
Try doing this.
Load up $user_info into your global declarations.
Input all the groups you want to show into an array.
$x = array(1, 2, 3); <= Group ID numbers you want to show the info to.
Then set a variable false. This is for a later step.
$y = false;
Then actually check out the $user_info variable and grab the data.
foreach ($x as $group) {
if( in_array( $group, $user_info['groups'] ) ) <= If the user is in a group defined in $y and that is defined in the groups context, then proceed.
$y = true; } <= If the data can be grabbed, then that variable is true.
Now, for the actual template part. Let's first check if the variable we set was true.
if( $y ) { <= Basically means that if $y is true, the continue
From this point, do your code.
echo '
<div>
Some other stuff here that you want to protect.
</div>'; }
So it would look like:
global $user_info;
$x = array(1, 2, 3);
$y = false;
foreach ($x as $group) {
if( in_array( $group, $user_info['groups'] ) )
$y = true; }
if( $y ) {
echo '
<div>
Some other stuff here that you want to protect.
</div>';
}
That's the advanced way of checking out a group. SMF comes with default values as well.
$context['user']['is_guest'] <= This checks if the user is in group 0.
$context['user']['is_logged'] <= This checks if the user is not in group 0
allowedTo('moderate_forum') <= This checks if the user has any moderator permissions. Eg, in groups 2 or 3.
$context['user']['is_admin'] <= This checks if the user is permitted to administrate the forum. Eg, in group 1.
Quote from: ccbtimewiz on August 08, 2008, 11:31:34 PM
Welcome to the world of PHP. :P
Try doing this.
Load up $user_info into your global declarations.
Input all the groups you want to show into an array.
$x = array(1, 2, 3); <= Their ID numbers.
Then set a variable false. This is for a later step.
$y = false;
Then let's actually check out the $user_info variable and grab the data.
foreach ($x as $group) {
if( in_array( $group, $user_info['groups'] ) )
$y = true; } <= If the data can be grabbed, then that variable is true.
Now, for the actual template part. Let's first check if the variable we set was true.
if( $y ) {
From this point, do your code.
echo '
<div>
Some other stuff here that you want to protect.
</div>'; }
So it would look like:
global $user_info;
$x = array(1, 2, 3);
$y = false;
foreach ($x as $group) {
if( in_array( $group, $user_info['groups'] ) )
$y = true; }
if( $y ) {
echo '
<div>
Some other stuff here that you want to protect.
</div>';
}
talk about welcome to the world of php
Wow. o.k so what if I wanted to use this method. If I put "$context['user']['is_logged']" would that allow access to anyone thats logged in?
$context['user']['is_guest'] <= This checks if the user is in group 0.
$context['user']['is_logged'] <= This checks if the user is not in group 0
allowedTo('moderate_forum') <= This checks if the user has any moderator permissions. Eg, in groups 2 or 3.
$context['user']['is_admin'] <= This checks if the user is permitted to administrate the forum. Eg, in group 1.
Yes it would.
Correct. :)
Likewise, !$context['user']['is_guest'] would work as well. The "!" means false. So, if the user isn't a guest.
Alright thanks :)