You are invited to Log in or Register a free Frihost Account!

[HELP] PHP (and some MyBB) Administration

ACP = Admin Control Pannel (FYI)

Now I know not everybody knows how to use MyBB coding, but I'll try to make this as clear as I possibly can.

I am trying to finish up this bit of code for administrators. Here are the codes needed:

(This variable is set in the ACP. My current variable is: 1)
($mybb->settings['admin_uids'] IS 1)
(The number 1 is the ID of the user viewing the page. Read further below for more detail.)

(This variable is called from a database. It's the users ID, which is auto_incremented, meaning you can never have the same ID as another user.)
(If a user that has the UID of 4, is logged in, and is viewing the page, then $mybb->user['uid'] would be 4.)

Now since my ID is 1, and the $mybb->settings['admin_uids'] CONTAINS the number 1, I use the following PHP code:


if ($mybb->user['uid'] == $mybb->settings['admin_uids'])
echo "You are logged in as an administrator.";

Which, if you are extremely confused, would also be:


if (1 == 1)
echo "You are logged in as an administrator.";

So to specify: Since my UID is the number 1 and the admin_uids variable is set as 1, I can see the message "You are logged in as an administrator.". Which I do..

Now what the problem is, if I try to add more then just the UID of 1 in the settings['admin_uids'], such as adding a , will make it think:


if (1 == 1, 2)
echo "You are logged in as an administrator.";

And obviously my ID isn't 1, 2.. What I CANNOT do (since this is a plugin that will be used by anybody) is add the ID's seperatly within the file. settings['admin_uids'] must call the variable that is stored in the ACP. I've tried using explode(), implode(), array(), but nothing seems to work right..


Those are the only 2 variables that I need to call that relates to the ID.

If there is anybody out there that can possibly help me, PLEASH DO! I already know that I've probably confused you, so if you have any questions please ask!

I feel that this is more of a tutorial then a help thread.. please don't see it as a tutorial (unless this actually helped you).

//convert the comma separated string into an array
$uidarray=explode(',' $mybb->settings['admin_uids']);

//check if uid is in the array
if ( in_array($mybb->user['uid'],  $uidarray) )
   echo "You are logged in as an administrator.";

rofl, next time just ask 'I have 2 variables and one must contain multiple numbers($var1), the other just one($var2). How can I see if the one number($var2) is mentioned in the variable with multiple numbers($var1)?' Razz

You can also use an array in the config instead of the explode, or you could use strpos() if you dont's want to use arrays.

Thanks for helping me with that, it works perfectly ^^. This'll help with some other things.. PHP rules ^^


Yea, I guess I should've used less words to get the point across xD. And I'm gonna go learn that strpos() to see what more I can use it for..

Thanks to the both of you ^^
Related topics
Zapraszam do mojej gry :)
[HELP] PHP -> Scripting
Needing a Bit Og Help {PHP}!
need some help - php switch code
[SUPORTE] Imagem de status do MSN
[man][help]PHP... What you think?
help,php books
Please help. php script installation error
I need help yet again
[help][php] Ayuda con las cadenas
Error with MySQL and PHP script in my CMS
Session directory permissions issue
[Help] php script to post to twitter
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.