phpBB3 external login

caiol611

New Member
Messages
7
Reaction score
1
Points
0
Hi,

I am using phpBB3 and wanted to have an external login box from a page that is outside the forum directory. I have searched all over the phpBB3 support forums and haven't much information that was useful.

So, what I would like to put on my site is a special login section with forms for username/password and a login button. After logging in, the code redirects to the forum index (/phpBB3/). If you return back to the personal website outside of the forum directory, and go back to the login area, only a logout button should appear. Clicking on the logout button goes to the forum page confirming logging out, then redirects to the home page of the personal website (outside of forum directory.

I myself am a n00b when it comes to programming (i only have basic knowledge of html but a bit on how to edit css and php).

The code that I found that works close to what I need is: http://area51.phpbb.com/phpBB/viewt...sid=e1a1fbe8c588a2205010f67e13431eea&start=10

PHP code goes in header
Code:
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);

PHP forms (basically html)
Code:
/* Start Logout*/
                     if ($user->data['is_registered']){
                     echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=logout&amp;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:");

The above code works for me, its only that I cant get the login/logout redirects to the pages that I want. Anyone with any phpBB3 modding experience? Any help is much appreciated.

Thanks
 
Last edited:

caiol611

New Member
Messages
7
Reaction score
1
Points
0
I got my problem solved ;)

So, on the top of my login.php file, which is outside of the forum directory (phpBB3/) and on my normal website, I put the following code:

Code:
<?php
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);

if($user->data['is_registered']){
redirect("$phpbb_root_path");
break;
}
?>

I was basically missing the:

Code:
 if($user->data['is_registered']){
redirect("$phpbb_root_path");
break;

which signifies if the user is registered, then clicking on the forum button links directly to the forum index, bypassing the login page.

On the same login.php in the body, I put the following code:

Code:
<h2>Login Panel</h2>
<?php

/*Start Logout*/
if ($user->data['is_registered']){
echo("<form method='post' action='".$phpbb_root_path."ucp.php?mode=logout&amp;sid=".$user->data['session_id']."'>");
echo("<input type='submit' name='logout' value='Logout'>");
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(" <input type='text' name='username' size='15' value=''>");
echo("<br /><br />");
echo(" Password:");
echo(" <input type='password' name='password' size='15' value=''>");
echo("<br /><br />");
echo("<input type='submit' name='login' value='Login'>");
echo("<br /></form>");
echo("<br />");
echo("Don't have an account? Please register <a href='phpBB3/ucp.php?mode=register'>here</a>.");
}
/*End Login Box*/
?>

This contains all the forms for the username/password plus a register link on the bottom.

Most of the code has been copied from codes already posted in the phpBB3 Support Forum. I hope that whoever plans to implement an external login panel in their website will find this useful.


Edit:
I also forgot an important piece that I forgot to mention....:happysad:

On line 95 in the ucp.php file under your phpBB3 directory, replace

Code:
meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")));

with

Code:
## LOGOUT REDIRECT HACK  -- BEGIN ##
$redirect = request_var('redirect', "../index.html");
meta_refresh(3, append_sid($redirect));
## LOGOUT REDIRECT HACK  -- END ##

Logging out of the forum redirects the user back to the homepage (or replace ../index.html with whatever page you want).

Hope this helps.
 
Last edited:

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
Thanks, I'll bookmark this and if I need it, I'll give you some rep.
:)
 

nutan.lade

New Member
Messages
2
Reaction score
0
Points
0
Hey I tried the above code but it is giving that config.php is not found and a link to install phpbb3.How to solve this one.Reply immediately please.
 

caiol611

New Member
Messages
7
Reaction score
1
Points
0
As I am not a PHP expert nor do I know much about programming, all I can say is that you should play around with the $phpbb_root_path setting and/or other areas that refer to a page. I have no idea how your site is structured so I guess it is simply adjusting the code to fit your site.
 

wolf693

New Member
Messages
112
Reaction score
0
Points
0
This is a good idea! I've seen it on a couple websites and never really had an idea on how it worked.
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
Thanks.
I've been looking for a way to do this for ages. I'll bookmark this page and give it a go when I have some spare time.
 

nutan.lade

New Member
Messages
2
Reaction score
0
Points
0
In the root of the web directory i have some web pages through which i need a xtrnal login.I already installed phpbb3 forums and it is located in forums directory.But while using the above script and I tried to login but it was saying that

The requested URL /'.$phpbb_root_path.'/ucp.php was not found on this server.

And the code i used in the webpage is

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

$phpbb_root_path = 'forums/';

$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);


Please solve the problem as soon as possible.

Thanq in advance....
 

caiol611

New Member
Messages
7
Reaction score
1
Points
0
So, your forum is placed inside a folder called "forums" which is inside the public_html folder, correct? If your login PHP page is located right under public_html but outside of your forum directory, you should have no problems. It looks to me that your code is correct. I dunno...:dunno:
 
Last edited:

kadaver

New Member
Messages
51
Reaction score
0
Points
0
Is it possible to use this as a way to validate a users access to restricted pages for registered users only. seperate logins take too much time for users to get to stuff on the site.

Currently my site uses Drupal and PHPBB3 with the forum as the master login and registration, I installed a plugin for Drupal to make this work but havent been able to reverse engineer it (??? some of the codeing is confusing) for my own use.

Ideas for how to get this to work? Thanks.
 

kkenny

Active Member
Messages
1,950
Reaction score
0
Points
36
Maybe you could try messing around with the cookies, like set in php that the user can only access if he has this certain cookie that phpbb gives (you can label the cookie in phpbb) I'm not sure how it would work, but it's a start.
 
Top