How to get users from forum to different part of site
#1
I've built PHP & Ajax Chatroom. It works pretty good, except I don't know how to integrate this so on the users who signed up on the forums can use it only.

I'm guessing I'd need to use the MyBB Cookies or Sessions, but I'm really kinda new to PHP to be able to think this through. (I'm good with javascript though)

Let's say the forum is on http://example.com/forum, and the chat is on http://example.com/chat. How can I get this chat room to work so it displays the current users on that page, and only allow the users to chat in it?

Reply
#2
To see if the user is currently online, you can load the core $mybb class (and other MyBB related things) by including global.php from inside you chat script:

<?php
	define("IN_MYBB", TRUE);
	require_once("../global.php");

	[...]

Then you can just check if the user is logged into the forum with something like this:

	[...]

	// If the user isn't logged in
	if ($mybb->session->uid == 0) {
		die("You need to be logged in to view this chatroom");
	} else {
		$user = get_user($mybb->session->uid);
	}

	[...]

$user will then be populated with everything you need to know about the user. You could then go on to check their usergroup and see if they're banned, too.

Not sure if that's what you meant, but feel free to elaborate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)