MyBB Community Forums

Full Version: [SOLVED]How to use cookies set by mybb member.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have read through the thread on how to integrating the forum login by redirecting my main site login form to member.php. My original code was making use of session to keep track of users on my main. How do I change the code to make it look at the login cookie set by mybb and what are the cookies that mybb set upon logging in?

<?php
session_start();
	if (!isset($_SESSION['userID'])) //if session is not set, userid will be set to public and login form will be displayed.
	{
		$_SESSION['userID'] = 'Public';
		$userID = $_SESSION['userID'];
	}
		$userID = $_SESSION['userID'];
		if ($userID === "Public")
		{
?>
<div class="loginform">
<form id="loginForm" name="loginForm" method="post" action="forum/member.php">
      UserID:
        <input name="username" type="text" id="username" size="8" />
Password:
<input name="password" type="password" id="password" size="8" />
<input type='hidden' name='action' value='do_login'>
<input type='hidden' name='url' value='http://www.datesyoumustknow.com'/>
<input type ="submit" name="Submit" value="Login" class="loginbutton" />
</form>
</div>
<?php
	}
	else
	{	
		$userName = $_SESSION['userName'];
		$userID = $_SESSION['userID'];
	}
?>
Feel kinda silly I am the only one replying in my own thread lolz, but I have solved the problem with this

<?php
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';

	session_start();
	//if(isset($_COOKIE['mybb'])) 
	if($mybb->user['uid'] > 0)
	{
		include 'inc/config.php';
		$userID = $mybb->user['username'];
		$userLogin = 'User has logged in';
	}
	
	else
	{
		$userID = 'Public';
		$userLogin = 'User has not logged in';
	}	
?>
Its always handy to post a solution if you find it - maybe it will help someone else one day.

And now you have someone else on the thread so it looks less daft Smile