MyBB Community Forums

Full Version: Integrating another script [HELP]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, I'm trying to integrate a script in the forum and it fetches the user info from the cookies. At first it used to work fine but then I started using a cookie prefix, the problem is that now it doesn't fetch any online users....
here's the get function.

Quote:function getUserID() {
$userid = 0;
if (!empty($_COOKIE['sid'])) {
$sql = ("SELECT ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX."sessions WHERE sid='".mysql_real_escape_string($_COOKIE['sid'])."'");
$query = mysql_query($sql);
$session = mysql_fetch_array($query);
$userid = $session[DB_USERTABLE_USERID];
}
return $userid;
}
I guess adding a cookie prefix variable might work........... Can you guys help me? I'll appreciate it very much.
HELP PLEASE!!!!!!!
HELP!!!!!!!!!still none of you guys look at this one.
I am not sure if you are fetching the details the right way. First of all, are you connected to mybb's database, or your custom script's database?

I have integrated some of my websites into websites and this is the logic that I have used:
* Upon registration
-> Create forum account (can send you the code if you don't have it yet)
* Upon login on the website (NOT the forum)
-> Log in to website and forward to forum_login.php
-> forum_login.php connects to mybb's database and selects the user with the same username (username is safer because if something gets messed up the user ID's wont match!) and sets the cookie.
	my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], null, true);
	my_setcookie("sid", $session->sid, -1, true);
-> forum_login.php redirects to account page

Basically, you are redirecting to forum_login.php which keeps your login separate, you can have it in the same file as your login script but it is always easier to edit it (plus i have solved function redeclaration problems this way).

This is not the only way, and maybe not the best way either, but with separate databases it worked well for me.