For many years, I’ve had full phpBB session integration on my site using this simple PHP snippet:
This allowed me to do things like:
…from anywhere on my site, outside phpBB itself.
For years, I’ve been planning to migrate to XenForo. But every time I searched for similar full-site integration with XenForo, I kept running into vague or discouraging answers. Most posts said it wasn’t possible or wasn’t recommended for some reason.
So I decided to experiment on my own and surprisingly I got it working.
Here's a minimal standalone snippet I wrote to access the current XenForo user session (username + user ID):
To explore more available data, I used:
Now, here are my questions:
It seems to work well for basic integration tasks, but I'd like to hear from others with deeper XenForo internals experience. Is this viable long-term? Any red flags I should watch out for?
Code:
define('IN_PHPBB', true);
$phpbb_root_path = ROOT_PATH . 'forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$request->enable_super_globals();
This allowed me to do things like:
Code:
echo json_encode($user->data['username']);
…from anywhere on my site, outside phpBB itself.
For years, I’ve been planning to migrate to XenForo. But every time I searched for similar full-site integration with XenForo, I kept running into vague or discouraging answers. Most posts said it wasn’t possible or wasn’t recommended for some reason.
So I decided to experiment on my own and surprisingly I got it working.
Here's a minimal standalone snippet I wrote to access the current XenForo user session (username + user ID):
Code:
if (!defined('XF_INCLUDED')) {
define('XF_INCLUDED', true);
if (!defined('XF_ROOT')) {
define('XF_ROOT', __DIR__ . '/forum');
}
require_once XF_ROOT . '/src/XF.php';
\XF::start(XF_ROOT . '/src/config.php');
$xf_app = \XF::setupApp('XF\Pub\App');
$xf_app->start();
$xf_session = $xf_app->session();
$xf_visitor = \XF::visitor();
}
if ($xf_visitor->user_id > 0) {
echo $xf_visitor->username;
echo $xf_visitor->user_id;
}
To explore more available data, I used:
Code:
print_r($_COOKIE);
print_r($xf_visitor->toArray());
Now, here are my questions:
- Why hasn’t this approach been suggested or documented more often? Am I overlooking something important, like security issues or best practice violation?
- Is there no community interest in this kind of full-site session integration? Or are there alternative, more "XenForo-approved" methods I should consider for live session integration?
It seems to work well for basic integration tasks, but I'd like to hear from others with deeper XenForo internals experience. Is this viable long-term? Any red flags I should watch out for?