PHPBB3 Login - Session Website Integration

Discussion forum for MOD Writers regarding MOD Development.
Wins
Registered User
Posts: 1
Joined: Sat Dec 22, 2007 6:51 pm

PHPBB3 Login - Session Website Integration

Post by Wins »

Hello All, i have just installed the new PHPBB3, and started to design/take notes of my website when i ran into something i were ensure i could do without someones help. Well what i need is a Login integration with PHPBB and the website. So here is my Design notes :

WEBSITE : HOME
----> Login : //*Enter User name and Password
-------> Correct : //*Redirect to Members Home
-------> Incorrect : //*Redirect to Home or a message underneath the login box with the error
------------>Members Home //Option to go to forums and logged in from session
-----------------> Browse Content // Content forum topic link -> go to forum topic logged from session

So basically i hope you can follow it, i also want a LOCK so, i can lock my non-member visitors from viewing
all the other pages without being logged in. I also want it to redirect depending on user group if possible.

Anyway know any ideas of where i can basically start, or even get some help.
I have found alot of other topics and supplies some answers, but is there a code already out
there to save me time, or base my code. If so please linky, and thank you ^^
kazurianproductions
Registered User
Posts: 15
Joined: Tue May 27, 2008 11:01 am

Re: PHPBB3 Login - Session Website Integration

Post by kazurianproductions »

I want something like this on my webstie too and i cant find anywhere that will help me :( Nobody on these forums is helping at the moment either :(
birk
Registered User
Posts: 43
Joined: Sun Dec 10, 2006 4:06 pm

Re: PHPBB3 Login - Session Website Integration

Post by birk »

User avatar
rhythm1
Registered User
Posts: 950
Joined: Sat May 10, 2008 9:23 pm
Location: Maldives

Re: PHPBB3 Login - Session Website Integration

Post by rhythm1 »

What you are trying to do is in this KB article: phpBB2 Sessions Integration Which is for PHPBB2, but there will be minor changes in 3 if any at all. The included files may differ, but you can go through another .php file from PHPBB3 and figure that out..
`Rhythm
I 'd rather live in a world with PHPBB
Where we stand and where we siT - Shit is bound to be always therE
oldgreyhair
Registered User
Posts: 37
Joined: Tue Feb 27, 2007 3:37 pm
Location: Kent, UK
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by oldgreyhair »

From what you are saying, I gather that you want full website integration where your site uses all the register and login facilities of phpBB. There are many levels that you can run this but that would be up to you how you wish to incorporate phpBB functions etc.

I have done a fairly basic integration with my site which is new and still under development, http://www.perception9.com/ It works for what I want. I must add that little of the following coding is my own, original work but a combination of coding by others that I managed to trawl, so thanks should go to them.

To do it –

At the very top of every page in your website proper put the code –

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
(Where I use the directory forum, change to your phpBB directory) This is the main integration code that carries everything through from phpBB to your main site.

Next put up a separate login page on your main site to include –

Code: Select all

<form method="post" action="forum/ucp.php?mode=login">
<label for="username">Username: </label> <input type="text" name="username" id="username" size="40" /><br /><br />
 <label for="password">Password: </label><input type="password" name="password" id="password" size="40" /><br /><br />
 <label for="autologin">Remember Me?: </label><input type="checkbox" name="autologin" id="autologin"  /><br /><br />
 <input type="submit" value="Log In" name="login" />
 <input type="hidden" name="redirect" value="../index.php" />
 </form>
You can take this page further by adding the ability to register from it by using a simple href such as –

Code: Select all

<a title="Register" href="forum/ucp.php?mode=register">Register</a>
Again forum is your phpBB directory and the login form will take you back to your website home page by way of the redirect after submit. If you want a lock, as you put it, to ensure only logged in members access pages, then make the login page your index page and call your website home page something else.

Once you are integrated, you can use a bit of a security feature on your include files by putting the following piece of code at the top of each file –

Code: Select all

<?php
if (!defined('IN_PHPBB'))
{
	exit;
}
?>
Or something similar with a little message to potential hackers.

I hope this helps.
kazurianproductions
Registered User
Posts: 15
Joined: Tue May 27, 2008 11:01 am

Re: PHPBB3 Login - Session Website Integration

Post by kazurianproductions »

oldgreyhair wrote:From what you are saying, I gather that you want full website integration where your site uses all the register and login facilities of phpBB. There are many levels that you can run this but that would be up to you how you wish to incorporate phpBB functions etc.

I have done a fairly basic integration with my site which is new and still under development, http://www.perception9.com/ It works for what I want. I must add that little of the following coding is my own, original work but a combination of coding by others that I managed to trawl, so thanks should go to them.

To do it –

At the very top of every page in your website proper put the code –

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
(Where I use the directory forum, change to your phpBB directory) This is the main integration code that carries everything through from phpBB to your main site.

Next put up a separate login page on your main site to include –

Code: Select all

<form method="post" action="forum/ucp.php?mode=login">
<label for="username">Username: </label> <input type="text" name="username" id="username" size="40" /><br /><br />
 <label for="password">Password: </label><input type="password" name="password" id="password" size="40" /><br /><br />
 <label for="autologin">Remember Me?: </label><input type="checkbox" name="autologin" id="autologin"  /><br /><br />
 <input type="submit" value="Log In" name="login" />
 <input type="hidden" name="redirect" value="../index.php" />
 </form>
You can take this page further by adding the ability to register from it by using a simple href such as –

Code: Select all

<a title="Register" href="forum/ucp.php?mode=register">Register</a>
Again forum is your phpBB directory and the login form will take you back to your website home page by way of the redirect after submit. If you want a lock, as you put it, to ensure only logged in members access pages, then make the login page your index page and call your website home page something else.

Once you are integrated, you can use a bit of a security feature on your include files by putting the following piece of code at the top of each file –

Code: Select all

<?php
if (!defined('IN_PHPBB'))
{
	exit;
}
?>
Or something similar with a little message to potential hackers.

I hope this helps.
Hey thanks this helps me a lot, but is there away to check whether a user is logged on and if so it will show the user's username but if they arent logged on it will show the login form?
Looking forward to yuor reply :D
User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10410
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by Noxwizard »

You can use this:

Code: Select all

if($user->data['is_registered'])
{
     echo 'Welcome ' . $user->data['username'];
} 
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.
User avatar
rhythm1
Registered User
Posts: 950
Joined: Sat May 10, 2008 9:23 pm
Location: Maldives

Re: PHPBB3 Login - Session Website Integration

Post by rhythm1 »

Here is another topic you may want to look at. http://www.phpbb.com/community/viewtopi ... a&start=60
`Rhythm
I 'd rather live in a world with PHPBB
Where we stand and where we siT - Shit is bound to be always therE
oldgreyhair
Registered User
Posts: 37
Joined: Tue Feb 27, 2007 3:37 pm
Location: Kent, UK
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by oldgreyhair »

The way I've incorporated a user status (logged in or not) bit onsite is -

Code: Select all

<?php
if($user->data['is_registered'])
//if($user->data['session_logged_in'])
     //user is logged in
{
     print $user->data['username'];
     echo'<span class="brightgreen"> is logged in</span><br />
     <a title="See You Later" href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id). '">Log out</a>';
}
else
     //user is not logged in  
{
     echo'You are not logged in<br /><a title="Log Yourself In" href="your log in page">Log In</a> or
          <a title="Register" href="forum/ucp.php?mode=register"> Register</a>';
}
?>
Don't worry about the colours or titles that I'm using, that's up to you. Also you can use a span or div to surround code to colour the other showing text.
lolmako
Registered User
Posts: 17
Joined: Thu Jul 10, 2008 4:59 am

Re: PHPBB3 Login - Session Website Integration

Post by lolmako »

Wrong thread, please delete post.
garethbraid
Registered User
Posts: 47
Joined: Thu Jul 26, 2007 4:58 pm
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by garethbraid »

Hi

I'm trying to restrict access to some pages using the following code as suggested at the beginning of this thread:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
However if I logout of the forum and go to the page that includes this code as above, I can access it OK.

Can anyone tell me where I'm going wrong, if they are not logged in we shouldn't be able to see the page, and re-direct to a login page.

Any help please guys, thank you in advance.
User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10410
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by Noxwizard »

That's because the code you used isn't supposed to restrict access, it simply carries the phpBB session over to that page. If you want to restrict access, then you need to put this after the session code:

Code: Select all

if(!$user->data['is_registered'])
{
    if ($user->data['user_id'] != ANONYMOUS)
    {
        trigger_error('NOT_AUTHORISED');
    }

    login_box('', $user->lang['NOT_AUTHORISED']);
} 
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.
garethbraid
Registered User
Posts: 47
Joined: Thu Jul 26, 2007 4:58 pm
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by garethbraid »

Noxwizard wrote:That's because the code you used isn't supposed to restrict access, it simply carries the phpBB session over to that page. If you want to restrict access, then you need to put this after the session code:

Code: Select all

if(!$user->data['is_registered'])
{
    if ($user->data['user_id'] != ANONYMOUS)
    {
        trigger_error('NOT_AUTHORISED');
    }

    login_box('', $user->lang['NOT_AUTHORISED']);
} 
Thanks for your help, is it possible to if not authorised to display a custom login form and a webpage rather than going to the phpbb style login screen.
User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 10410
Joined: Mon Jun 27, 2005 8:41 pm
Location: Texas, USA
Name: Patrick Webster
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by Noxwizard »

Yes, you would just print out your HTML in that if statement, rather than a call to trigger_error() and login_box().
[Support Template] - [Read Before Posting] - [phpBB Knowledge Base]
Do not contact me for private support, please share the question in our forums.
garethbraid
Registered User
Posts: 47
Joined: Thu Jul 26, 2007 4:58 pm
Contact:

Re: PHPBB3 Login - Session Website Integration

Post by garethbraid »

OK, thank you - will have to work out how to do that.

You've been a great help, very much appreciated.
Locked

Return to “[3.0.x] MOD Writers Discussion”