A Better Place to Redirect Users After Logging In

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
stevenmw
Registered User
Posts: 34
Joined: Sat Jun 22, 2013 5:19 pm

A Better Place to Redirect Users After Logging In

Post by stevenmw »

I feel there should be better functionality when simply wanting to incorporate phpBB itself and phpBB features with a website.

Here is my feature request. The ability to be taken back to your previous viewed page after logging in. No matter if you are in the forum path or outside of it, and long as each page is defined in phpBB and you are using phpBB's sessions. With this small implementation you can use phpBB features hand in hand with your website without any effort. This is a tiny feature to implement and it really propels phpBB. There wouldn't need to be any new major core features added, the idea is that this implementation just helps to better use what is all ready in the core. What are your thoughts?

I know there is a mod called Prime Login Redirect, but that is really just for inside of the forum path.

When I implements PhpBB into a site I'm just wanting to use the features of PhpBB in my site. For instance with PhpBB I have a messaging system, user system, registration system, user profiles, and threads that can even be used to display news feeds. Not to mention the awesome forum itself. Of course the main feature I am after is the authentication and sessions.

I recently read a thread about phpBB and full site integration found here https://www.phpbb.com/community/viewtopic.php?p=4016875. What I think PhpBB 4 should have is some kind of simplified way of integrating PhpBB with websites. I am talking about just making it simpler to use the PhpBB system with a developer's site. This wouldn't require anything other than changing the way pages are redirected. No more going to the forum index every time.

Right now when you want to login you can set your form action to ./phpBB3/ucp.php?mode=login. If a user is successfully logged in they are taken to the index set inside of the forum path. By simply altering this so that is redirects you to the page you were previously even if it is outside of the forum path solves everything. You now have a login script that no matter where you are on the site whether it is inside or outside of the forum path you are taken back to where you were before logging in. This simple redirect practically incorporates PhpBB with the site.

All you have to do is make sure you incorporate PhpBB's sessions and define the pages in PhpBB like so.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? 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();
?>

Your existing page goes here
More info can be founder here, https://www.phpbb.com/kb/article/phpbb3 ... tegration/

Here is how I incorporate PhpBB into my site.

My login form looks like

Code: Select all

 <form action="./bb/ucp.php?mode=login" method="post">
 <label for="username">Username:</label>
 <input type="text" name="username" id="username" title="Username" />
 <label for="password">Password:</label>
 <input type="password" name="password" id="password" title="Password" />
 <input type="hidden" name="return" value="<?php echo($_SERVER['REQUEST_URI']); ?>" />
 <label for="autologin">save info<input type="checkbox" name="autologin" class="autologin" /></label>
 <input type="submit" name="login" value="Login" class="headsub-submit" />
</form>
The link I included above says to use a hidden field like this to redirect your user

Code: Select all

<input type="hidden" name="redirect" value="./somefile.html" />
The problem with this is that it takes you to a set page, not the page you were at before logging in. So what I do is store the url in a hidden field like so

Code: Select all

<input type="hidden" name="return" value="<?php echo($_SERVER['REQUEST_URI']); ?>" />
Then I go to my functions.php found at /include/functions.php and on line 3041 and 3042 you'll see this

Code: Select all

 $redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");
 $message = ($l_success) ? $l_success : $user->lang['LOGIN_REDIRECT'];
I change it to

Code: Select all

$goback = $_POST['return'];
$redirect = request_var('redirect', $goback);
Of course every page outside of the forum path that I create has to have this at the top

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? 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();
?>
I put the above code in a php file and simply include it at the top of all of my pages.

To do this all I had to do was create a hidden input field, store the url, and change one line and add another in my functions.php


The thing about it is that this is a very poor way to do it, but it is probably one of the simplest ways to incorporate phpBB into a website. Obviously it needs to be sanitized and several other things should be applied to the $_POST[' '].. This is just how I have it working right now.

I really believe that by simply redirecting a user to their previous page after logging in whether inside or outside of the forum path is all it takes to really allow phpBB to be incorporated into web sites with no fuss. Thanks for reading.

Post Reply