Login Integration 3.2.X

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Login Integration 3.2.X

Post by ZyrusOfficial »

I am trying to integrate the login system that is provided by phpbb with my entire website. So it would go like this:

Index.php - Main domain access
Login.php - Log in for entire site

So when people Login or Register, it automatically goes through phpbb. So instead of people logging in through my website and then having to separately log in to the phpbb, they would have seamlessly logged in on phpbb as well.

I would love to have this and it would make my website absolutely perfect. Please consider this <333
User avatar
david63
Registered User
Posts: 18301
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Login Integration 3.2.X

Post by david63 »

It is almost impossible to create a generic login integration between phpBB and a "custom" site - especially without knowing the first thing about the site and its login process, or even having a link to the site.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

david63 wrote:
Sun Dec 09, 2018 9:00 am
It is almost impossible to create a generic login integration between phpBB and a "custom" site - especially without knowing the first thing about the site and its login process, or even having a link to the site.
My website is http://www.zyrusofficial.xyz/ and the forum are located at http://www.zyrusofficial.xyz/forum

I am most likely going to use this login system: https://www.tutorialrepublic.com/php-tu ... system.php unless there is a better one to use...
User avatar
david63
Registered User
Posts: 18301
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Login Integration 3.2.X

Post by david63 »

As you have not as yet created your site I would suggest that you look at using the phpBB login system as your main login routine for your site rather than trying to integrate phpBB with another login system. You should look at using the phpBB Pages extension to add your other content that way everything is in one place and far easier to manage.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

david63 wrote:
Sun Dec 09, 2018 10:53 am
As you have not as yet created your site I would suggest that you look at using the phpBB login system as your main login routine for your site rather than trying to integrate phpBB with another login system. You should look at using the phpBB Pages extension to add your other content that way everything is in one place and far easier to manage.
I've been looking into it and I dug up two things that might be useful for this... Thoughts?

https://www.phpbb.com/support/docs/en/3 ... tegration/
https://www.phpbb.com/support/docs/en/3 ... tegration/


EDIT: I might have struck gold..

viewtopic.php?f=71&t=719055
User avatar
david63
Registered User
Posts: 18301
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Login Integration 3.2.X

Post by david63 »

ZyrusOfficial wrote:
Sun Dec 09, 2018 11:34 am
I've been looking into it and I dug up two things that might be useful for this... Thoughts?
Probably will not work
ZyrusOfficial wrote:
Sun Dec 09, 2018 11:34 am
EDIT: I might have struck gold..

viewtopic.php?f=71&t=719055
No you haven't - those instructions are for phpBB 3.0 and will not work with phpBB 3.2
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

david63 wrote:
Sun Dec 09, 2018 11:57 am
ZyrusOfficial wrote:
Sun Dec 09, 2018 11:34 am
I've been looking into it and I dug up two things that might be useful for this... Thoughts?
Probably will not work
ZyrusOfficial wrote:
Sun Dec 09, 2018 11:34 am
EDIT: I might have struck gold..

viewtopic.php?f=71&t=719055
No you haven't - those instructions are for phpBB 3.0 and will not work with phpBB 3.2
Well I've attempted to start implementing and the login does work. It allows me to log in, and the login is successful, but is not redirecting to home.php, instead it keeps me at login.php... Signing out is also bugged and throws an error, but I'll look at it later when I can :P. Here's my login.php

Code: Select all

<?php
function display_login_box()
{
   echo 'Please log in:<br /><form method="POST" action="/login.php">
   <p>Username: <input type="text" name="username" size="40"><br />
   Password: <input type="password" name="password" size="40"><br />
   Remember Me?: <input type="checkbox" name="autologin"><br />
   <input type="submit" value="Submit" name="login"></p>
   <input type="hidden" name="redirect" value="'.$current_page.'">
   </form>';
}
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();
if($user->data['is_registered'])
 {
  //User is already logged in
  echo "You're already logged in!"; 
 }
 else
 {
  $username = request_var('username', '', true);
  $password = request_var('password', '', true);
  $autologin = (!empty($_POST['autologin'])) ? true : false;

  $result = $auth->login($username, $password, $autologin);

  if ($result['status'] == LOGIN_SUCCESS)
  {
    //User was successfully logged in
    //Redirect to the page they were viewing
    $redirect = request_var('redirect', "home.php");

    // append/replace SID
    $redirect = reapply_sid($redirect);

    meta_refresh(0, $redirect);
   }
   else
   {
    display_login_box();
   }

 }
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login | ZyrusOfficial</title>
</head>

</html>
I am essentially working on straight backend to make everything work seamless before I begin to make everything look pretty and have an actual website.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 26731
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Login Integration 3.2.X

Post by Paul »

Why not use the functions phpBB already provided to do stuff? Like this:

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();
if($user->data['is_registered'])
 {
  //User is already logged in
  echo "You're already logged in!"; 
 }
 else
 {
  login_box();
 }
?>
I suggest you also fully build your website around phpBB, using the template stuff from phpBB, and everything included (And even better, not creating new files, but writing extensions and using the routing system instead).
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
User avatar
GanstaZ
Registered User
Posts: 804
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Login Integration 3.2.X

Post by GanstaZ »

Like mentioned above by Paul and David, you do not need any extra stuff/files for register and login. phpbb can be integrated to anything and anywhere. If your site and board are in the same root, routes and controllers is the best thing to do & nothing extra is needed.
If your site is in root and board in sub-folder, you can use as mentioned already,

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();
or make a front controller that is connected to phpbb system and load whatever is needed. Easiest way is to go with routes and controllers (building your site as extension).
"When answer lies in the question,.. question becomes redundant!"
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

GanstaZ wrote:
Sun Dec 09, 2018 2:43 pm
Like mentioned above by Paul and David, you do not need any extra stuff/files for register and login. phpbb can be integrated to anything and anywhere. If your site and board are in the same root, routes and controllers is the best thing to do & nothing extra is needed.
If your site is in root and board in sub-folder, you can use as mentioned already,

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();
or make a front controller that is connected to phpbb system and load whatever is needed. Easiest way is to go with routes and controllers (building your site as extension).
I would rather not redirect to the login page of my forums. I want to make my website a full integration so that way there is no need for the login page of the forum or register.
User avatar
Lumpy Burgertushie
Registered User
Posts: 68111
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Login Integration 3.2.X

Post by Lumpy Burgertushie »

then create your whole website using phpbb alone.

you create whatever other pages you want for the website using either the pages extension or just manually using the old instructions found in the knowledgebase.

you can create whatever html pages you wish. they don't have to look like the board if you don't want them to.

or, you can create your html pages and then design the board style to look like them .

you can change the code for the redirect code to redirect to wherever you want.



robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

If nobody is in the forest, does a tree really fall?
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

Here is the current problem I am running in to:

The login system works perfectly and redirects as needed to my home.php
My register system works just as well and redirects as needed.

Now my home.php is having a problem with this line:

include($phpbb_root_path . 'common.' . $phpEx);

Here is my home.php in full:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if($user->data['is_registered'])
{
    //User is already logged in
}
else
{
    $username = request_var('username', '', true);
    $password = request_var('password', '', true);
    $autologin = (!empty($_POST['autologin'])) ? true : false;

    $result = $auth->login($username, $password, $autologin);

    if ($result['status'] == LOGIN_SUCCESS)
    {
        //User was successfully logged into phpBB
        $redirect = request_var('redirect', "login.php");

        // append/replace SID
        $redirect = reapply_sid($redirect);

        meta_refresh(0, $redirect);
        trigger_error('You have been successfully logged in');
    }
    else
    {
        //User's login failed
    }
}
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home | Zyrus Official</title>
</head>
<body>
    <div class="page-header">
        <h1>Welcome back, <b><?php echo htmlspecialchars($_SESSION["username"]); ?>!</b></h1>
    </div>
    <p>
        <a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
    </p>
</body>
</html>
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

Here is the current problem I am running in to:

The login system works perfectly and redirects as needed to my home.php
My register system works just as well and redirects as needed.

Now my home.php is having a problem with this line:

include($phpbb_root_path . 'common.' . $phpEx);

Here is my home.php in full:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if($user->data['is_registered'])
{
    //User is already logged in
}
else
{
    $username = request_var('username', '', true);
    $password = request_var('password', '', true);
    $autologin = (!empty($_POST['autologin'])) ? true : false;

    $result = $auth->login($username, $password, $autologin);

    if ($result['status'] == LOGIN_SUCCESS)
    {
        //User was successfully logged into phpBB
        $redirect = request_var('redirect', "login.php");

        // append/replace SID
        $redirect = reapply_sid($redirect);

        meta_refresh(0, $redirect);
        trigger_error('You have been successfully logged in');
    }
    else
    {
        //User's login failed
    }
}
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home | Zyrus Official</title>
</head>
<body>
    <div class="page-header">
        <h1>Welcome back, <b><?php echo htmlspecialchars($_SESSION["username"]); ?>!</b></h1>
    </div>
    <p>
        <a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
    </p>
</body>
</html>
If the problem exists in my config.php, here is that as well:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('/forum')) ? PHPBB_ROOT_PATH : './'; //PHPBB_ROOT_PATH
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
?>
Did not mean to bump, sorry.
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Login Integration 3.2.X

Post by ZyrusOfficial »

So I've been discussing with some members on how to make this possible, and I have a pretty good starting base for people to use.

Everything redirects/logs in/registers correctly from what I can gather. If you want a live version of this to test and such, I am currently using it on my website: http://www.zyrusofficial.xyz


Here is what I have so far:

Login.php

Code: Select all

<?php
function display_login_box()
{
   echo 'Please log in:<br /><form method="POST" action="/login.php">
   <p>Username: <input type="text" name="username" size="40"><br />
   Password: <input type="password" name="password" size="40"><br />
   Remember Me?: <input type="checkbox" name="autologin"><br />
   <input type="submit" value="Submit" name="login"></p>
   <input type="hidden" name="redirect" value="'.$current_page.'">
   </form>';
}
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();
if($user->data['is_registered'])
 {
  //User is already logged in
      echo "You are Logged In! Redirecting you shortly.."; 
 }
 else
 {
  $username = request_var('username', '', true);
  $password = request_var('password', '', true);
  $autologin = (!empty($_POST['autologin'])) ? true : false;

  $result = $auth->login($username, $password, $autologin);

  if ($result['status'] == LOGIN_SUCCESS)
  {

    // append/replace SID
    $redirect = reapply_sid($redirect);

    meta_refresh(0, $redirect);
    
    //User was successfully logged in
    //Redirect to the page they were viewing
    header( "refresh:1;url=home.php" );
      
      
   }
   else
   {
    display_login_box();
   }

 }
?>
 
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>YOUR TITLE HERE</title>
</head>
</html>
Register.php

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ucp');
 
if($user->data['is_registered'])
{
        meta_refresh(3, append_sid("home.php"));
        trigger_error("You are already registered!");
}
 
$submit = request_var('submit', '');
if($submit)
{
        // Retrieve default group ID
        $sql = 'SELECT group_id
                FROM ' . GROUPS_TABLE . "
                WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
                        AND group_type = " . GROUP_SPECIAL;
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
 
        if (!$row)
        {
                trigger_error('NO_GROUP');
        }
        $group_id = $row['group_id'];
        
 
        $data = array(
                'username'                      => utf8_normalize_nfc(request_var('username', '', true)),
                'user_password'         => phpbb_hash(request_var('password', '', true)),
                'user_email'            => strtolower(request_var('email', '')),
                'group_id'                      => (int) $group_id,
                'user_type'                     => USER_NORMAL,
                'user_ip'                       => $user->ip,
        );
        
        $validate_username = validate_username($data['username']);
        if ($validate_username !== false)
        {
                trigger_error($validate_username, E_USER_ERROR);
        }
        
        $validate_password = validate_password($data['user_password']);
        if ($validate_password !== false)
        {
          trigger_error($validate_password, E_USER_ERROR);
        }
        
        //UNQUOTE WHEN EMAIL ACTIVATION IS REQUIRED ELSE BREAKS REGISTER SYSTEM
        //$validate_email = validate_email($data['user_email']);
        //if ($validate_email !== false)
        //{
        // trigger_error($validate_email, E_USER_ERROR);
        //}
        
        $user_id = user_add($data);
 
        if ($user_id === false)
        {
                trigger_error('NO_USER', E_USER_ERROR);
        }
 
        //Set up welcome message
        if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable'])
        {
                $message = $user->lang['ACCOUNT_INACTIVE'];
        }
        else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable'])
        {
                $message = $user->lang['ACCOUNT_INACTIVE_ADMIN'];
        }
        else
        {
                $message = $user->lang['ACCOUNT_ADDED'];
        }
        
        //Display message
        $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
        trigger_error($message);
}
else
{
        echo '<form action="./register.php" method="post">
              Username: <input type="text" name="username" /><br />
              E-mail address: <input type="text" name="email" size="25" maxlength="100" /><br />
              Password: <input type="password" name="password" size="25" /><br />
              <input type="submit" name="submit" value="Submit" />
              </form>';
}
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>YOUR TITLE HERE</title>
</head>
</html>
Config.php

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('/forum')) ? PHPBB_ROOT_PATH : './'; //PHPBB_ROOT_PATH
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
?>
Home.php

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

if($user->data['is_registered'])
{
    //User is already logged in
}
else
{
    $username = request_var('username', '', true);
    $password = request_var('password', '', true);
    $autologin = (!empty($_POST['autologin'])) ? true : false;

    $result = $auth->login($username, $password, $autologin);

    if ($result['status'] == LOGIN_SUCCESS)
    {
        //User was successfully logged into phpBB
        $redirect = request_var('redirect', "login.php");

        // append/replace SID
        $redirect = reapply_sid($redirect);

        meta_refresh(0, $redirect);
        trigger_error('You have been successfully logged in');
    }
    else
    {
        //User's login failed
    }
}
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home | Zyrus Official</title>
</head>
<body>
    <div class="page-header">
        <h1>Welcome back, <b><?php echo htmlspecialchars($_SESSION["username"]); ?>!</b></h1>
    </div>
    <p>
        <a href="logout.php" class="btn btn-danger">Log Out</a>
    </p>
</body>
</html>
Logout.php

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './phpBB3/';    //Path to forum
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ucp');

if($user->data['is_registered'])
{
    $user->session_kill();
    $user->session_begin();

    $redirect = request_var('redirect', "index.$phpEx");
    meta_refresh(1, $redirect);
    
    trigger_error('LOGOUT_REDIRECT');
}
else
{
    trigger_error('LOGOUT_FAILED');
}
?>
Known Problems/Errors:

On Home.php, it will not display the username. It's a simple fix and I'm sure someone will post a fix on here somewhere.

Not an error, but I have the email validation //'d out currently until I make it so when people register, they have to activate their account via email.
Last edited by ZyrusOfficial on Sun Dec 09, 2018 11:12 pm, edited 2 times in total.
ZyrusOfficial
Registered User
Posts: 32
Joined: Sun Dec 09, 2018 7:36 am

Re: Login Integration 3.2.X

Post by ZyrusOfficial »

</Solidjeuh> wrote:
Sun Dec 09, 2018 10:57 pm
I'm not a mod, just saying... viewtopic.php?f=641&t=2494691 :D
Yes that was the post I made about asking about it. I posted here to gather all information I've received and to help others.
Post Reply

Return to “phpBB Custom Coding”