News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to use is_not_guest(); ?

Started by Elmacik, October 21, 2005, 04:50:33 AM

Previous topic - Next topic

Elmacik

1-i want to add something to my index, but dont want to be viewed by guests..
i thought i can use is_not_guest(); thingy.
but how to limit it to a specific location? wherever i put this, everything below it becomes invisible to guests.
even the copyright...
i think this is clear enough.... (?)
i tried to put if($context['user']['is_guest']) but still doesnt show below  is_not_guest();

2-and maybe i can check if surfer is a user (can be gmod, mod, standard user or admin).
but i know how to use only  $context['user']['is_admin']   is_gmod or is_guest
how to check for a "member" only? (for not using is_not_guest(); )

3-and whats the difference between:  $context['user']  and !$user_info['']  ?
4-and where are the "global" functions saved? -- i looked in sources folder but i didnt see a "global" definition. i know i am bad at php :)

5-and a last question, am i asking much? :P tolerate me, i am trying to learn :P
Home of Elmacik

xenovanis

if($context['user']['is_guest']) means 'if the user is a guest, he can do the following action'.


if(!$context['user']['is_guest']) means 'if the user is a guest he can not do the following action'. You can also use if($context['user']['is_logged'] for that.
"Insanity: doing the same thing over and over again and expecting different results."

Elmacik

aha, i didnt notice that exclamation!
thanks..
how can i use an "or" command?
for example i want to check if the user is in group SOMETHING or in group OTHERTHING  ?
and the same question for the "and" command..
Home of Elmacik

xenovanis

I suppose you could use something like this

if (in_array(1, $user_info['groups']) or in_array(2, $user_info['groups']))
if (in_array(1, $user_info['groups']) || in_array(2, $user_info['groups']))

if (in_array(1, $user_info['groups']) and in_array(2, $user_info['groups']))
if (in_array(1, $user_info['groups']) & in_array(2, $user_info['groups']))

Where 1 and 2 or the id's of your usergroups. You probably need to add user_info to the globals of the file you want to make changes in. But remember, I'm not a real coder, I learned by trial and error  ;) There may be a better way.
"Insanity: doing the same thing over and over again and expecting different results."

1MileCrash

Quote from: Elmacik on October 21, 2005, 06:41:57 AM
aha, i didnt notice that exclamation!
thanks..
how can i use an "or" command?
for example i want to check if the user is in group SOMETHING or in group OTHERTHING  ?
and the same question for the "and" command..

you can use the same thing, one for if it is false, one for if it is true. The two '' side by side mean "show nothing". Putting something there will show when false.

this would be inside an echo'.  xenovanis's code will be before/outside an echo. either will work fine though.

' , $context['user']['is_logged'] ? 'This is what a logged in user will see. if its true' : 'this is what a guest will see. it is false' , '

The only thing php can't do is tell you how much milk is left in the fridge.



Elmacik

xenovanis
i didnt use arrays and just used or with context, it worked.. i dont know if i am doing the right thing though :P
you helped me a lot! muchas gracias :D

one question more,
the user groups i create takes place in context? or do i have to create them myself?
(i mean this:   $context['user']['is_newlycreatedgroup']  )
Home of Elmacik

Elmacik

Tippmaster thanks for the tip :)
and what if i dont use in echo? (like we discussed above)
i mean how many data will be shown to guests if i use:
if($context['user']['is_guest'])

an echo will be shown to this guest? or everything below that line?
Home of Elmacik

1MileCrash

#7
let me give you an example. This is my chat page, simplified. it uses an else statement so that guests cannot view it.


<?php
if($context['user']['is_logged'])
{
    echo '
<applet 
codebase="http://www.freejavachat.com/java/" 
archive="http://www.freejavachat.com/java/cr.zip" 
code="ConferenceRoom.class" 
name=cr 
width=500 
height=300>
<param name=ssp value="/params/lite.prm">
<param name=channel value="#model98.org">
<param name=nick value="">

<center>
This application requires Java suport.<br>
This server also available via IRC at:<br>
<A HREF="irc://irc.ircstorm.net:6667">irc.ircstorm.net:6667</a>
</center>
</applet><br>
Please be respectful in the chat!'
;
}
else
echo 
"Sorry, only registered users are allowed to access our chat. Please <a href=\"http://model98.org/forum/index.php?action=login\">log in</a> or <a href=\"http://model98.org/forum/index.php?action=register\">Register</a><p>
"

?>



as you can see, logged in users will se the applet. guests will see "Sorry, only registered users are allowed to access our chat. Please <a href=\"http://model98.org/forum/index.php?action=login\">log in</a> or <a href=\"http://model98.org/forum/index.php?action=register\">Register</a><p>"

you almost have to use an echo somewhere...in order to actually display something, unless it's just more dynamic content. The IF in my chat page and xenovanis showed you is for before an echo. Everything between the { and } gets displayed for a logged in user. after that, the else takes over. Else, meaning 'other than logged', which would be a guest.

for your first problem, use the brackets. If i understand correctly, your problem is that everything below the if you put is invisible to guest, but you dont want all of that invisible to guest.
notice the brackets ("{"). They end the if.

if($context['user']['is_logged'])
{
    echo 'this will be viewable by logged in users only';
}
echo' This willl show for everyone';


so for your second question, you want to limit it to only certain members? This is also do-able. See the simple example below.

if ($context['user']['name']=="Tippmaster")
echo "hey tippmaster";
else
echo "you wish you were as cool as tippmaster";


i just used an IF to check if the user's name was tippmaster. If it is, it will display "hey Tippmaster". If it is any other user of the forum, it will display "you wish you were as cool as tippmaster".  You can do this to limit anything from anybody. In fact, you can do it the other way around, if you want. (allowing access to everyone BUT one person).

So..
if ($context['user']['name']=="Elmacik ")
echo "hey elmacik";
else
echo "hey....not...elmacik";


if you want it only accessible to gmods, w.e., etc. you can use basically the same thing, but with a different variable/value. find the id of that members group.

if (in_array(1, $user_info['groups']))
   {
       echo ' shows if the member is in group one ';
   }
else
   {
       echo 'shows if the member is in any other group.';
   }


The only thing php can't do is tell you how much milk is left in the fridge.



Elmacik

Tippmaster, thanks a lot for the info,
for the second question, i didnt mean the member name, i meant membergroup.
for example if i have a membergroup thats named writer.
does this regular or standard member group take place in context?
or do i have to creat it myself, i mean, will i be able to use this for example:
if ($context['user']['is_writer']).......


one other thing:
i knew if statement is used with brackets. and may i use also else?
like: if (condition) {{ action } else (condition 2) {action 2}}
Home of Elmacik

1MileCrash

i edited my post for member group aswell.  :)

i think i understand what you mean now, but it's really similar to my chat page. It uses both brackets and else.


if($context['user']['is_logged'])
{
    echo 'shows for logged in users';
}
else
echo "shows for logged out users..";


is this what you want?

The only thing php can't do is tell you how much milk is left in the fridge.



Elmacik

Home of Elmacik

Advertisement: