1 (edited by Maxtrix 2007-03-21 20:39)

Topic: external login / logout

I would like punBB to use the information from an existing table in the DB for username/password.  Basically people have registered on a game I have programmed, and now that Im adding forums I dont want them to have to re-register.  Is this possible without a whole lot of re-writing and editing? If so, please tell me how.

Help is rally appreciated!

Re: external login / logout

Well, PunBB is going to be looking for the columns it wants for users. You might be better off simply having your registration process create an account for the user in PunBB and have your login process log them in to the forum and the game.

Re: external login / logout

Yeah, I thought about that, but it seems a bit ineffcient and edgy from a programmers point of view.

Re: external login / logout

Well, it seems a better solution than editing your table to add PunBB's columns or PunBB's table to add your columns smile
When integrating two system which are already fully developed, I think it's better to keep both systems intact. Especially when they may have columns that do the same thing but in a contradictory way (ie: storing passwords hashed versus unhashed)

Re: external login / logout

Hmm, okay, you've convinced me.

6 (edited by Maxtrix 2007-03-21 05:38)

Re: external login / logout

How exactly would I go about logging a user into punBB?  It uses cookies, not sessions, I havent worked with those before.

EDIT: After looking at several posts here and the include/functions.php file I still don't understand.  I have to use " pun_setcookie($user_id, $password_hash, $expire);" to log people in?

Re: external login / logout

You're on the right track. First thing you need to do is add PunBB's common.php to your pages. Then, when you login to your game, you'll want to call that function, where $user_id is their ID in PunBB's user table, $password_hash is the user's password as taken from PunBB's users table, and $expire is whatever you feel like (since you're using sessions, setting it to 0 will make it act like a session). That will set the cookie and PunBB's check_cookie function should deal with the rest.

8 (edited by Maxtrix 2007-03-21 20:50)

Re: external login / logout

Yep, that worked perfectly.  For anyone who's interested in this (rather simple code) to log people in, here it is:

$result_pun = mysql_query("select `id` from `f_users` where `username`='$username' ");
$row_pun = mysql_fetch_array($result_pun);
pun_setcookie ($row_pun['id'], pun_hash($origpassword), time() + 86400);

and the logout looks like this:

setcookie('punbb_cookie', "", 31536000, "/");
mysql_query(" DELETE FROM `f_online` WHERE `user_id`='$userid' ");
$ctime = time();
mysql_query(" UPDATE `f_users` SET `last_visit`='$ctime' WHERE `id`='$userid' ");

edit: it turns out that the above code only worked on my offline server.  On a real server/domain, its punBB doesnt recognize the cookie :S