MyBB Community Forums

Full Version: How to check log in personally ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello fellow MYBB Admirers Smile

I installed mybb on my linux localhost yesterday and its well and smooth working

i plan to launch a site with mybb as forum script and also the site has some extra script custom made running on it

now mybb and custom made script have their own cookie checking , registration etc.

i want to have a common registration i.e via mybb
That is simple , to users redirect to mybb registration thing

but now how do i check if a user is logged in or not , and if logged in , which user out of mybb

I mean how to check whether user is logged in or not in my domain running mybb in root

i tried including functions.php , global.php and functions_user.php

but it made things messy

please let me know some better alternative if you have.

Just want to check if user is logged in or not and if logged in , want username , userid as details

thats it Smile

PleasE HElP
How is including global.php messing things up?
You have to define MYBB_ROOT and include global.php relatively.

define('IN_MYBB', true);
define('MYBB_ROOT', "/path/to/mybb/");
include_once "./forum/global.php";

So the include needs to be a relative path starting from the current directory. If you are working in the root of your domain and your forum is in a directory called "forum". The relative path to the global.php is: ./forum/global.php

The MYBB_ROOT is an absolute path. Which means that it is the directory structure starting from the server root folder. If you want to know the absolute path of your forum, read this post:
http://community.mybb.com/thread-96573-p...#pid706451
(2011-06-20, 10:14 AM)Aries-Belgium Wrote: [ -> ]How is including global.php messing things up?
You have to define MYBB_ROOT and include global.php relatively.

define('IN_MYBB', true);
define('MYBB_ROOT', "/path/to/mybb/");
include_once "./forum/global.php";

So the include needs to be a relative path starting from the current directory. If you are working in the root of your domain and your forum is in a directory called "forum". The relative path to the global.php is: ./forum/global.php

The MYBB_ROOT is an absolute path. Which means that it is the directory structure starting from the server root folder. If you want to know the absolute path of your forum, read this post:
http://community.mybb.com/thread-96573-p...#pid706451

wow repute added

that was fully what i lacked

its working \m/
hey one more thing left

i can do session checking and stuffs
but in mybb
how do i generate those links

logout.php?loginkey

do help me on that Sad
You mean the login/logout-key?
The loginkey is stored in the user table and the logoutkey is the md5 hash of the loginkey.
I saw that Aries-Belgium nbut i wanted to know is there any method defined to call that via included files i.e global , functions , functions_user

if there exists a method already it would be better rather than me writing select key from users etc etc. SQL Statements Smile
If you want to know it for the currently logged in user, you can use $mybb->user['loginkey'] . Or you can use the following to get the loginkey for another user (uid 2 for instance):
$user = get_user(2);
echo $user['loginkey'];
But the latter also selects the information from the database.
worked!!!!!!!

Thakns a ton
hi, i'm also trying to check if i am logged in, but username or uid are not set/empty
here is my code
define('IN_MYBB', true);
define('MYBB_ROOT', "../myBBforum/");

include_once "../myBBforum/global.php";

echo $mybb->user['uid'].'<br>';
echo $mybb->user['username'].'<br>';

do i need something else ?
MYBB_ROOT needs to be the absolute path. Check this link to know what the absolute path is for your forum: http://community.mybb.com/thread-96573-p...#pid706451

Also make sure the cookiepath include the parent folder. If you run your forum on www.domain.com/mybbForum/ and your script www.domain/script/ ... Your cookiepath needs to be: /
thanks, working now