Log in

View Full Version : integrating phpbb users to the rest of my site



james438
07-31-2010, 10:29 PM
I was just thinking of adding the ability to add comments to my articles by people using a login feature and cookies. I thought about building my own when a friend suggested integrating the user system from my phpbb forum. Is this fairly easy to do or should I just create my own username/password database?

fastsol1
08-01-2010, 12:10 AM
I haven't actually watched this yet but I think this is pretty close to what you want

http://www.youtube.com/user/phpacademy#p/u/18/Jq4csat4jNU

james438
08-01-2010, 05:59 AM
Yes, this does, thanks. I have only watched the first few minutes so far, but this certainly does help.

djr33
08-01-2010, 02:06 PM
I've done this a few times with other software (such as SMF) and it works well. It takes a significant amount of time to understand the complex programming of the board (from what I recall, phpbb is not simple, to say the least, though not much more complex than other forums), but once you understand it everything is simpler.

If your goal is to integrate with the forum (use the forum and use your site), then this is a good idea.

If your goal is to only borrow from the forum and not actually use it, this will probably be more work for you because you will need to shortcut all of the user operations like login, registration, change password, etc. And somehow disable the forum while keeping the system running for integration.

Beverleyh
08-01-2010, 02:41 PM
Hi James,

I've done this with both a phpbb2 and phpbb3 forum software so logged in members get special menus, stylesheets and content across the whole site. Admins get their own special admin tools and facilities too.

I've also crossed phpbb3 integration across sub-domains of a site.

Let me know your own particular plans/setup and be only too pleased to help.

james438
08-02-2010, 11:17 AM
Well, mostly what I want to do is to let visitors be able to write comments or questions on individual articles/pages. I was thinking that the best way to do this would be to integrate the login system that my phpbb3 forum currently uses so as to save myself a bit of coding and maybe make it so that users only need to log in to one place and be able to post in both the forum and the rest of my site. Mind you my site gets no visitors as it is really only a hobby site for myself and at $5 a month certainly well worth it :).

I am wondering if it might be easier to write my own script though instead and use my own user table for this purpose as I am not too keen on decrypting phpbb's password system.

Beverleyh
08-02-2010, 12:00 PM
There's not much to decrypt really - in fact you can achieve rather a lot by pasting in a short block of code on every page (.php) of your site.

For phpbb3;

Paste this at the very top of each page - change the path to phpbb3 to suit:

<?php
define('IN_PHPBB', true);
// Specify the path to your phpBB3 installation directory.
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>

Here are some code examples;


<!-- if user is logged in show members stylesheet else show default stylesheet -->
<?php
if($user->data['is_registered'])
{echo "<link href=\"http://www.mywebsite/styles/members.css\" rel=\"stylesheet\" type=\"text/css\">";}
else
{echo "<link href=\"http://www.mywebsite/styles/default.css\" rel=\"stylesheet\" type=\"text/css\">";}
?>


<?php if($user->data['is_registered'])
{
print $user->data['username'];
echo' is logged in<br />
<a title="Log out" href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id). '">Log out</a>';
}
else
{
echo 'You are not logged in<br /><a title="Log in" href="login_page.php">Log In</a> or <a title="Register" href="forum/ucp.php?mode=register"> Register Now</a>!';
}
?>

You can specify usergroups or even individual users like this;

<!-- If Admin or bobtest is logged in show content else show alternative -->
<?php if (($user->data['group_id'] == 11902) || ($user->data['username'] == 'bobtest')) { ?>
You are logged in as Admin or bobtest
<?php } else { ?>
Who are you? Some random Joe off the street?
<?php } ?>
You can find your group ID (in my example, the Admin group is 11902) by logging into the ACP, going to the "General" tab and selecting "Manage groups" on the left (under QUICK ACCESS)
Then select "Members" and look in the URL - it's the number on the very end.

So, using combinations of the code above you can protect your content/scripts/online tools and serve them to logged-in members or specific groups, or just yourself.

This thread got me started: http://www.phpbb.com/community/viewtopic.php?p=4016875&sid=9e8c137126bdef2ba45bec223b360577#p4016875

Hope that helps :)

BTW -You also need to check to make sure the cookie is set to cover the whole domain and not just the phpbb3 forum. To do that, go to the "General" tab again, right at the bottom select "Cookie settings" (under SERVER CONFIGURATION) and set the cookie path to "/". And the cookie domain should just be something like ".mywebsite.com".

I also read somewhere that the number of dots in the cookie domain can affect things so if you have a .co.uk wesbite, you might have to set the cookie domain to "mywebsite.co.uk" - the 2 dots are still there but at the end - this was definitely a factor on phpbb2 but it may have been corrected in phpbb3.

james438
08-03-2010, 12:48 AM
Much appreciated, thanks. I think that I will use phpbb to integrate the users with the rest of my site. I still need to set up a block of time to update my site, but it looks like you did most of the work for me :)

Later,
James438

Beverleyh
08-03-2010, 07:33 AM
If the members database/login system is already there, you might aswell use it :)

Glad I could help anyway.