News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Get user name from SMF cookie on My Website build with SSI

Started by ZoRk, May 07, 2012, 04:09:36 PM

Previous topic - Next topic

ZoRk

Hi, i have made my first website, around my 2.0.2 smf forum. 8)
I'm using PHP/SQL and some SSI's functions like the login one.

But now i got a problem:

I want to recuperate member name and a custom profile field on my website from the SMF cookie...
I need it for exemple to display an admin buton on navigation bar if the watcher is in admin group in the forum.
Don't worry, my site's admin space is protected by an .htacess


No problem for finding the fields with MySQL if i had member ID, or name, but how can i get it from the cookie?

Thanks.
www.CreAtiveCrafts.fr Serveur Minecraft PVP/RP/FB et communauté de joueurs

Matthew K.

Why not use the SSI function to pull the menu? Which should automatically add the admin button if they are allowed to view it.

ZoRk

Thank Labradoodle, but
this is not what i want.
 
My menu bar is different, and the admin section i want to use isn't the one of the forum, but one for controling and monitoring my Game server and a daily rewards game on the website.

I know it was possible to get user id from the cookie with smf 1.x but how can i make that with smf 2.0.2 ?
www.CreAtiveCrafts.fr Serveur Minecraft PVP/RP/FB et communauté de joueurs

Matthew K.

You can globalize $context or $user_info and do something like: if ($user_info['is_admin'])

ZoRk

Sorry, i'm just learning php by myself (and google), can you give a little more explanations?

Where does this variables come? And how my site could know they are linkto my forum?

www.CreAtiveCrafts.fr Serveur Minecraft PVP/RP/FB et communauté de joueurs

Matthew K.

global $user_info;
if ($user_info['is_admin'])
echo 'Hello Admin!';

ZoRk

Great, it seems to work... :) Your a boss!!!

But i also want my forum's super modos to see this ADMIN button...

And i'd like to recuperate member id to get the custom profil field and use it for things like display member avatar and personnal stats from our game.

Sorry if ask so much...

Where can i found all the array fields for $user_info ?

EDIT: i'm stupid, will do a print_r... But if there is a documentation, i take it, for curiosity...

Edit, fantastic, i've seen all i want printing the array... I have member name, id... Just wonder why the [is_modo] is empty for the forum's global modérators...
www.CreAtiveCrafts.fr Serveur Minecraft PVP/RP/FB et communauté de joueurs

Matthew K.

Try cross-checking the $user_info['groups'] array to see if the array contains the global moderators id.

Arantor

Or allowedTo('moderate_forum') is probably a safer method.

Matthew K.

Why is that a more safe method? Because more groups could have it...?

Arantor

Firstly, it means you're not having to dig around getting ids, and if you later create a new group that is a form of global moderator, it'll just work here too, rather than having to figure it out then as to why it isn't working.

Anything you write you should expect to have to change in 6 months, just in case.

Matthew K.

Yeah, you're correct. But using the group ids wouldn't be a horrible solution. Using allowedTo(); would be more flexible.

ZoRk

I already made it with $user_info['groups'] Work fine. :)

How can y do with allowedTo('moderate_forum') ? I'm curious...

The syntax to use i mean, i'm just using PHP/SQL for couple of weeks so...I'm bad... :-\

Ps: What the hell makes custom_profile field's datas in the smf-theme table :o? Took me 15 minutes to find it...
www.CreAtiveCrafts.fr Serveur Minecraft PVP/RP/FB et communauté de joueurs

Matthew K.

allowedTo('permission_name'); is the syntax, it's a function that returns a boolean (true | false) on whether the user can perform that operation or has that permission.

http://support.simplemachines.org/function_db/index.php?action=view_function;id=408

the isAllowedTo(); function is identical, although it is fatal rather than returning a bool.

CapadY

Quote from: ZoRk on May 07, 2012, 07:23:40 PM
Where can i found all the array fields for $user_info ?

Try this:

print_r($user_info);

;)
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Matthew K.

Quote from: CapadY on May 08, 2012, 02:27:26 AM
Quote from: ZoRk on May 07, 2012, 07:23:40 PM
Where can i found all the array fields for $user_info ?

Try this:

print_r($user_info);

;)
Quote from: Topic StarterEDIT: i'm stupid, will do a print_r... But if there is a documentation, i take it, for curiosity...

Arantor

There is so little real documentation about SMF's innards, it's unreal.

Advertisement: