Customizing SMF > SMF Coding Discussion

SMF check if the user is logged on

(1/2) > >>

Laloeka:
Hello community,

I was searching how to do this, but I couldn't really find it anywhere. My goal is to make a chat-window in the theme template, which only shows when the user is logged on. That by itself isn't really hard to do.

My question is: How can I check if an user has logged on to the forum from another PHP file (for example: chat.php), where the chat messages are sent to, and are received by the chat-window in the forum page. I know it's possible, but I'm not sure how.

Can anyone help me with this? :)

Thanks!

NanoSector:
Hi Laloeka, welcome to SMF!

Have you already included SSI.php in that PHP file?

If so, do this for every user:

--- Code: ---loadMemberData(userid);
--- End code ---

And don't forget to global $user_profile.

Then, you can use this:

--- Code: ---$is_online[id] = $user_profile[id]['is_online'] === 0 ? false : true;
--- End code ---
Replacing id with the user ID.

Then you can use $is_online[id] to check if an user is online.

Laloeka:
That's great, thanks! :)

NanoSector:
No problem :)
If your topic is solved, please hit that green button below :)

Kryzen:
Ehm shouldn't this be in coding discussion? :P

Navigation

[0] Message Index

[#] Next page

Go to full version