How to integrate website login with PHPBB3

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 6873 Views - Last Post: 11 September 2013 - 11:17 AM Rate Topic: -----

#31 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 06 September 2013 - 03:51 PM

The User::Initialise code and the User class is optional, it's what I tend to use though. User::Initialise by itself won't do anything, it just allows you to safely use the other methods in the User class. If you use the User class and initialise it, then you can replace your line 20 above with this:
if (User::IsAnon())


...which I find more readable. It's up to you whether you use the User class at all, you don't need to, though you do get the benefit of not having to call global $user everywhere you want to query the phpBB user information.

The main reason I implemented the User class in my code was to integrate phpBB with my application. I have User tables in both my phpBB database and my application database, which have a 1-1 relationship, but in my application database I store settings that are local to the application not phpBB. Centralising code for all user manipulation and interaction was my motivation for creating the User class.
Was This Post Helpful? 0
  • +
  • -

#32 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 164
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 10 September 2013 - 05:57 AM

I find that it appears to be partially working.

<?php 
//Display Errors
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);

define('IN_PHPBB', TRUE);
$phpEx = 'php';
$phpbb_root_path = './phpBB3/';
include './phpBB3/includes/startup.php';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';
 
// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();


// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}

if ($user->data['user_id'] == ANONYMOUS) {
   echo 'Please login!';
} else {
   echo 'Thanks for logging in, ' . $user->data['username_clean'];
}


// Other PHP code



So when I load my index.php I see "Please login" at the top (as expected) and then an area to log in. When I log in it forwards me to a page that says "Thanks for logging in, MyUsername". All is well but when I go to another page it says "Please login". It doesn't matter what page I set, the first one always gets my login information but once I leave that page it shows me as not being logged in.

Also, when I log in it flashes the PHPBB3 "Successfully logged in, click here if you're not automatically redirected" screen. I'm not sure if there's something I must copy from the code that page references in order to pass the user login and/or session data.

This post has been edited by Logik22: 10 September 2013 - 06:09 AM

Was This Post Helpful? 0
  • +
  • -

#33 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 164
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 10 September 2013 - 08:46 AM

I think this is an issue with cookies.

It works correctly when I manually append the session ID to the end of the URL. How can I troubleshoot this?
Was This Post Helpful? 1
  • +
  • -

#34 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 10 September 2013 - 04:28 PM

It is a cookies issue, I've had this too. I still get the SID showing in the URL when I do this, I haven't looked into it properly, but it is definitely down to cookies. Here's some links to help you investigate the solution:
phpBB community link
phpbuilder forum post
Proposed solution by a blogger

If any of these work, would you mind posting back here, or PMing me, as it will save me some time when I go to fix it on my forums :)
Was This Post Helpful? 0
  • +
  • -

#35 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 164
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 11 September 2013 - 11:17 AM

I ended up making another post for this to make it a little more specific. Unfortunately I don't know if my solution would even apply to your situation.

http://www.dreaminco...7&#entry1900757


I think I got it working a little better. So now it recognizes who is logged in while on other pages without having the SID in the URL. My situation is probably a little weird but I will try to explain it the best I can.

I use PHPBB3 forums as my login method. So I have a regular HTML login area but it submits it to the PHPBB3 code to be authenticated/hashed/etc and then it redirects me to my Home.php. I have that logic here:
http://www.dreaminco...0&#entry1900417

On top of that I have my web page and PHPBB3 forums hosted from home on a QNAP (NAS) so you don't always interact with a NAS the same as you would a network resource hosted by a company.


Anyway, to resolve this issue I went in to my PHPBB3 forums Admin Control Panel. Under the Cookie section I set the forum domain to my external IP, not the internal IP of the QNAP.

https://www.phpbb.co...ookie-settings/

Quote

What are our cookie settings?
There are a several methods to change your cookie settings. But of course, before we're going to change the cookie settings we first have to know what our cookie settings are. So here are some examples to give you an idea what your Cookie settings are.

The examples

Example 1:
This is your board URL: http://example.com/phpBB3
Your cookie settings should be:

Cookie domain: .example.com (Note the dot at the beginning!)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.

Example 2:
This is my board URL: http://forums.example.com
Your cookie settings should be:

Cookie domain: forums.example.com (Note that there is no http:// at the beginning and no slash at the end.)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.

Example 3:
This is my board URL: http://example.co.uk
Your cookie settings should be:

Cookie domain: .example.co.uk (Yes, three dots in this scenario because the the tld has 2 and there needs to be one in the front)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.


So, I hope this helped you determine what your cookie settings should be.

The methods to change

Now you have to edit the settings. That's possible by several methods. I'll explain them. :)

1. The ACP
phpBB3 has the option to manually change your Cookie settings in the ACP.

First go to the window to edit your settings. :)
You can find it here: ACP ==> Tab "General" ==> Server configuration ==> Cookie settings
Here fill in your new cookie settings. Very simple.

2. A special file
It's also possible that when your cookie settings are incorrect you can't access your board anymore. So we made another solution. A special file that makes it possible to update your cookie settings. This solution is with thanks to ktuk.net

First of all copy the following code and give the file the name cookie.php, upload it in to your forum root where the board's config.php file is.

CODE: SELECT ALL
<?php

/**
*
* @package Cookie and server settings tool
* @copyright © 2008 ktuk.net
* @copyright © 2011 phpbb.com
* @license GPL
*
*/

// Standard definitions/includes
$page_title = 'phpBB3 Cookies';
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);

$cookie_data = array();
$server_data = array();
$sent = request_var('sent', '');

// Gather cookie settings from config array
$cookie_data[] = $config['cookie_domain'];
$cookie_data[] = $config['cookie_name'];
$cookie_data[] = $config['cookie_path'];
$cookie_data[] = $config['cookie_secure'];

$server_data[] = $config['force_server_vars'];
$server_data[] = $config['script_path'];
$server_data[] = $config['server_name'];
$server_data[] = $config['server_port'];
$server_data[] = $config['server_protocol'];

$cookie_checked = ($cookie_data[3]) ? "checked = \"checked\"" : '';
$force_checked = ($server_data[0]) ? "checked = \"checked\"" : '';

if (!$sent)
{
print "<html>
<head><title>$page_title</title></head>
<body>
<form action=\"" . $_SERVER['SCRIPT_NAME'] . "\" method=\"post\"
<fieldset>
<table>
<tr><h2>Cookie Settings</h2></tr>
<tr><td>Cookie Domain:</td><td><input type=\"text\" name=\"cookie_domain\" value=\"" . $cookie_data[0] . "\"></td></tr>
<tr><td>Cookie Name:</td><td><input type=\"text\" name=\"cookie_name\" value=\"" . $cookie_data[1] . "\"></td></tr>
<tr><td>Cookie Path:</td><td><input type=\"text\" name=\"cookie_path\" value=\"" . $cookie_data[2] . "\"></td></tr>
<tr><td>Cookie Secure:</td><td><input type=\"checkbox\" name=\"cookie_secure\" value=\"1\" $cookie_checked ></td></tr>
</table>

<table>
<tr><h2>Server Settings</h2></tr>
<tr><td>Force Server Vars:</td><td><input type=\"checkbox\" name=\"force_server_vars\" value=\"1\" $force_checked ></td></tr>
<tr><td>Script Path:</td><td><input type=\"text\" name=\"script_path\" value=\"" . $server_data[1] . "\"></td></tr>
<tr><td>Server Name:</td><td><input type=\"text\" name=\"server_name\" value=\"" . $server_data[2] . "\"></td></tr>
<tr><td>Server Port:</td><td><input type=\"text\" name=\"server_port\" value=\"" . $server_data[3] . "\"></td></tr>
<tr><td>Server Protocol:</td><td><input type=\"text\" name=\"server_protocol\" value=\"" . $server_data[4] . "\"></td></tr>
<tr><td>Submit:</td><td><input type=\"submit\" name=\"sent\" value=\"submit\"></td></tr>
</table>
</fieldset>
</body>
<html>
";
}

if ($sent)
{
$cookie_domain = request_var('cookie_domain', '');
$cookie_name = request_var('cookie_name', '');
$cookie_path = request_var('cookie_path', '');
$cookie_secure = request_var('cookie_secure', 0);
$force_server_vars = request_var('force_server_vars', 0);
$script_path = request_var('script_path', '');
$server_name = request_var('server_name', '');
$server_port = request_var('server_port', 80);
$server_protocol = request_var('server_protocol', 'http://');

$sql_ary = array(
'cookie_domain' => $cookie_domain,
'cookie_name' => $cookie_name,
'cookie_path' => $cookie_path,
'cookie_secure' => $cookie_secure,
'force_server_vars' => $force_server_vars,
'script_path' => $script_path,
'server_name' => $server_name,
'server_port' => $server_port,
'server_protocol' => $server_protocol
);

foreach ($sql_ary as $config_name => $config_value)
{
set_config($config_name, $config_value);
}

print "Settings are updated!";
print "<meta http-equiv=\"refresh\" content=\"2;./cookie.php\">";
}

?>

Browse to the script at its URI in your web browser, for example http://www.example.c...orum/cookie.php The script will then load a form showing your current server and cookie details which you can amend to the correct settings. Once you have got the settings edited correctly, click the submit button. After you're finished don't forgot to remove the script from your server. Otherwise everyone can edit your settings.

3. The database
Another possibility is using the database to run a query that updates your cookie settings. Go to phpMyAdmin and run the following query:

CODE: SELECT ALL
UPDATE phpbb_config SET config_value = 'YOUR COOKIE DOMAIN HERE' WHERE config_name = 'cookie_domain';
UPDATE phpbb_config SET config_value = 'YOUR COOKIE NAME HERE' WHERE config_name = 'cookie_name';
UPDATE phpbb_config SET config_value = 'YOUR COOKIE PATH HERE' WHERE config_name = 'cookie_path';
UPDATE phpbb_config SET config_value = '0' WHERE config_name = 'cookie_secure';

Please note that you have to replace the first 3 with your settings and for the last one you only edit the zero when you have Cookie Secure enabled, otherwise you don't do anything with it. Also note that when your table prefix is not phpbb_ you have to edit it to your database table prefix, and don't forget to purge the cache by removing all files from the cache folder except index.htm and .htaccess. :)

So, I hope your cookie settings are correct now and you can enjoy the "Log me on automatically each visit" option!

Updates:
08-02-2010 JimA - Added Example 3
07/12/2011 stevemaury - Removed backticks from SQL and made some grammatical corrections. Also changed "index.html" to index.htm".
7Dec2011 Dícky - Removed SQL queries from cookie.php and replaced with functions
KNOWLEDGE BASE
Knowledge Base
SUPPORT SECTIONS
Documentation
Flash Tutorials
Support Forums
IRC Support
International Support

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3