Using phpBB sessions with 3.2 (external pages to board) ?

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
Post Reply
Lascard
Registered User
Posts: 8
Joined: Tue May 22, 2018 6:23 pm

Using phpBB sessions with 3.2 (external pages to board) ?

Post by Lascard »

Hi,

Does this still work with version 3.2 ? the same way or similar code ??

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

I haven't seen any update to this tutorial and since i need to convert a 3.0.x phpBB board to 3.2 i want to ascertain i can still use sessions on the same site on pages outside the board

Many thanks for your help
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3738
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by Kailey »

After a quick look, it may, but since it was wrote for 3.0 some principles may be different. I'd be interested in hearing the outcome if you decide to try it.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
My little corner of the world, where I sometimes post things documented from my job.
Lascard
Registered User
Posts: 8
Joined: Tue May 22, 2018 6:23 pm

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by Lascard »

Thanks Kailey for your feedback.

Since converting the site with the 3.0.x board to 3.2 is no small endeavor, i would need to test on a new forum/ dummy site to see how it goes first.

Unless someone else is already using these phpbb sessions with the 3.2 version successfully ?
Tkx
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by GanstaZ »

It doesn't differ that much, depends on what you want to achieve and how. It worked for me before i switched to extension & front controller development. Don't remember everything in that topic, but it should work til we reach 3.3 or higher.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
Lascard
Registered User
Posts: 8
Joined: Tue May 22, 2018 6:23 pm

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by Lascard »

Thanks for your feedback.
Right now these phpBB sessions are used on site pages outside the phpBB board so the content is only seen to registered users and/or belonging to one specific group.
I'd like to extend this across the whole site (without using a bridge to another CMS) by just adding the phpBB sessions first in the header of these external pages.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by GanstaZ »

If forum path is correct in all those files where you want to use session, then there will be no problems.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
Lascard
Registered User
Posts: 8
Joined: Tue May 22, 2018 6:23 pm

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by Lascard »

kinerity wrote: Tue May 22, 2018 6:41 pm I'd be interested in hearing the outcome if you decide to try it.
Following GanstaZ feedback, I run a simple test (see below) with a phpbb3.2.2 board version and apparently it works OK

Code (coded with my feet, pls. upgrade !) to get user name, group name and print the relevant content if user belongs to the right group

Code: Select all

<?php 
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();

//$auth->acl($user->data);
//$user->setup();

		
if ($user->data['user_id'] != ANONYMOUS)   
{  
	$usera = ucfirst($user->data['username_clean']);	
	$groupnumber= $user->data['group_id'];
	
//$db->sql_query($sql);

$sql = 'SELECT group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $groupnumber;
			
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$groupname=$row['group_name'];	
		$db->sql_freeresult($result);
		
		
	
	echo ('<h4>Hello  '.$usera.'&nbsp;!</h4><p>You are a member of this group : "'.$groupname.'"</p> ');
		
		
		if ($groupnumber == "number i.e. group_id of your board premium group")
		{echo '<p><h2>Hello premium group member !</h2></p>'; 
		}
		else
		{echo 'You are not allowed to see this page premium content'; 
		}			
}		
else 
{echo '<h4>Please <a href="'.$phpbb_root_path.'ucp.php?mode=login">login</a></h4>'; 
}

?>
WackOo
Registered User
Posts: 8
Joined: Sat Jan 27, 2018 3:05 pm

Re: Using phpBB sessions with 3.2 (external pages to board) ?

Post by WackOo »

At first, sorry for bumping an old thread, but it's exactly about what I'm experiencing.

I'm trying to convert my front-end custom made website and phpbb forum from 3.0.13-PL1 to 3.2.8
So far so good, updating phpBB wasn't an issue, the problem I'm running into are cross use of sessions.

When I'm logged in into the updated forum, the sessions work and stay active.
As soon as I go to my updated front-end and refresh the page, the session breaks even for the forum ( 3.2.8 ).

I've tried several stuff, with and without for example

Code: Select all

$user->setup()
and/or

Code: Select all

$user->update_session_infos()
but haven't had any luck.
Also tried different ROOT_PATH's without success.

The first/original part of php code below works like a charm on the custom made php page with phpBB 3.0.13-PL1 for the user sessions.

1. Original, working on the old version of the website:

Code: Select all

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

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
2. Another try with full root_path:

Code: Select all

<?php
define('IN_PHPBB', true);
define('ROOT_PATH', "/var/www/vhosts/domainname.extension/httpdocs/forums");

if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
	exit();
}

$phpEx = "php";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
include($phpbb_root_path . 'common.' . $phpEx);

$request->enable_super_globals();

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$user->update_session_infos();
Does anyone have any suggestions or experiences on this matter?
Post Reply

Return to “phpBB Custom Coding”