How to create login forphpbb3 on website

Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here.
Forum rules
Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here. Feature requests are closed.
GodfatherUk
Registered User
Posts: 14
Joined: Tue Feb 28, 2006 10:55 pm

Re: How to create login forphpbb3 on website

Post by GodfatherUk »

A basic login/logout can look as follows.

At the head of your page, you need

Code: Select all

define('IN_PHPBB', true);
define('PHPBB_ROOT_PATH', './phpBB3/');

$phpbb_root_path = 'phpBB3/';

$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
The actual Login/Logout box:

Code: Select all

           /* Start Logout*/
                     if ($user->data['is_registered']){
                     echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=logout&sid=".$user->data['session_id']."'>");
                     echo("<input type='submit' name='logout' value='Logout'>");
 			echo("<input type='hidden' name='redirect' value='../index.php'>"); 
                     echo("<br /></form>");
                     }
                    /*End Logout*/

                     /*Start Login Box*/
                     if (!$user->data['is_registered']){
                                echo("form method='post' action='".$phpbb_root_path."ucp.php?mode=login'>");
                                echo(" Username:");
                                echo("<br />");
                                echo(" <input type='text' name='username' size='15' value=''>");
                                echo("<br /><br />");
                                echo(" Password:");
                                echo("<br />");
                                echo(" <input type='password' name='password' size='15' value=''>");
                                echo("<br /><br />");
                                echo("<input type='submit' name='login' value='Login'>");
                                echo("<input type='hidden' name='redirect' value='../".$_SERVER['PHP_SELF']."'>"); 
                                echo("<br /></form>");
                       }
                      /*End Login Box*/
This is a working code that I currently use on two websites.
The redirect bit in the login box takes the user back to the page they logged in from no matter where it is on the website.
You could do the same with the logout of needed :-)

User avatar
karlsemple
Registered User
Posts: 480
Joined: Mon Jan 23, 2006 8:49 am
Location: Hereford
Contact:

Re: How to create login forphpbb3 on website

Post by karlsemple »

Not entirely sure how this falls into the "Discussion" bracket for which this forum is intended.

themahdii
Registered User
Posts: 1
Joined: Wed Sep 10, 2008 3:27 pm

Re: How to create login forphpbb3 on website

Post by themahdii »

Hey guys, Not sure if people are still looking at this page, but I found it via a google search and it has answered alot of my questions so I want to thank you. I also wanted to offer some code that I came up with piggy backing off of the code you guys have for a logout button that redirects to the page you came from outside of the phpbb directory. So here it is in a form button ::

Code: Select all

<form method="post" action="<?php echo $phpbb_root_path.'ucp.php?mode=logout&sid='.$user->data['session_id'].'&redirect='.'http://www.YOURSITEHERE.com'.$_SERVER['PHP_SELF']; ?>">
<input type="submit" value="Log Out" />
</form>
And here as just a regular link:

Code: Select all

<a href="<?php echo $phpbb_root_path.'ucp.php?mode=logout&sid='.$user->data['session_id'].'&redirect='.'http://www.YOURSITEHERE.com'.$_SERVER['PHP_SELF']; ?>">
Again thank you for all of your help, and I hope this helps!

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: How to create login forphpbb3 on website

Post by Highway of Life »

$_SERVER['PHP_SELF'] is vulnerable to XSS (Cross-site scripting).

phpBB does have it’s own $user->page array, so you could use $user->page['page_name']; But in the redirect param, you would use something like: append_sid($phpbb_root_path . $user->page['page_name'])
Image

faelzindc
Registered User
Posts: 1
Joined: Thu Oct 30, 2008 8:11 pm

Re: How to create login forphpbb3 on website

Post by faelzindc »

how to verify that the user is logged administrator, or moderator or a normal user?
(google translator ;S)

thanks ;)

SugarD-x
Registered User
Posts: 1
Joined: Wed Jan 28, 2009 1:01 am

Re: How to create login forphpbb3 on website

Post by SugarD-x »

Hello Area 51 users. I was wondering if there was any HTML-version of this code that I could use to do the same thing as above. I do not have access to, or the ability to modify my webhost's .htaccess file, so I cannot use PHP in my current .html files without converting them, which I do not want to do. Any help would be much appreciated. Please note also that I want it to work the same way as mentioned in the PHP code. I don't want it to redirect to me the forums already logged in. I already have it set up that way and I would rather it redirect back to the same page I was on with the log-in information stating the user as logged in, like in the PHP code above. Currently, my forums and website are separate and I do not wish to recode everything to make this work. My website is located at ./ whereas my forums are at ./forums/ and I have no plans of making a portal.

annu
Registered User
Posts: 1
Joined: Tue Apr 07, 2009 5:21 am

Re: How to create login forphpbb3 on website

Post by annu »

Hi...

I have integrated phpBB in my site in which i will have a login option, after getting logged in only i can access the phpBB that is there in my site. Now when ever i have logged in and when i click on phpBB it has to open with my login details automatically.so it has to use my members table rather than `phpBB_`'s member table.


Can any one suggest me, how can i approach for this...

Regards,
Annu :)

Post Reply