1 (edited by wenzlerpaul 2007-08-11 13:55)

Topic: [How To] Integrating punbb user login to any site

Hi,

I have been playing around some system and tried to integrate punbb user authentication to the current php authentication of the other system.

Since punbb authentication is based on cookies, I tried to come up with the best solution for my session based authentication and here is what I came up with:

Note:
main site is on www.domain.com and punbb is on www.domain.com/forum

//for punbb login and function access
define('PUN_ROOT', './forum/');
require PUN_ROOT.'include/common.php';

//punbb authentication variables to match my root variables
$groupid = $pun_user['g_id'];
$username = $pun_user['username'];
$useremail = $pun_user['email'];
$userid = $pun_user['id'];

//if you will want to use the current cookie info and set your session
$_SESSION[uid]=$userid;
$_SESSION[uname]=$username;

Include these codes into your common called files like config.php or header.php or common.php or whatever file that is universally used or included by all of your external/public files.

Now, if you wish to protect a section or the entire page, you can call the punbb function into your php page:

if($pun_user['is_guest']==1) {
//redirect or do whatever you want for guests only
}else{
//member section content
}

or if you wish to block access to entire page, just call it like:

if($pun_user['is_guest']==1) {
//put your message to guests here or include header or footer or ask them to login
exit();
}

As you can see on the above setup, I have my main site on the root and punbb on forum/ but I wanted to use the punbb authentication on the root.

I simply matched my site variables to that of punbb cookie variables to authenticate properly.  This method will allow you to call most or all of functions of punbb right on your root site, however, you may need to play around with it a little bit more.

As for the Session based variables, it functions normally for me because once the cookie is logged off, of course, it will set a new session, so my session is simply taking a ride on whatever is set on the cookie, this is just a workaround for me due to the nature of what I am currently working at and may not apply to you, so just play around with it.

I am not sure if someone already posted these information but I just wanted to share.

Paul