[FIXED] Accessing PHPBB via script on a sub-domain

Discussion forum for MOD Writers regarding MOD Development.
Locked
potiron
Registered User
Posts: 61
Joined: Wed Dec 01, 2004 9:55 am

[FIXED] Accessing PHPBB via script on a sub-domain

Post by potiron »

Hello,

I am trying to automatically insert users who register in another database, and to do so when I validate them on the website admin interface.
NB: all websites are on the same server.
Forum is on http://www.example.com/forums/
and my cms admin interface is on admin.example.com

On the script I run on the admin interface I try:

Code: Select all

function importPhpBB($user_detail)
{
	$phpbb_root_path = "/home/example/forums/";

	$phpEx = substr(strrchr(__FILE__, '.'), 1);
	echo $phpbb_root_path . "common." . $phpEx;
	define('IN_PHPBB',true);
	require_once( $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();

...etc.
My problem is: as soon as I do require_once( $phpbb_root_path . "common." . $phpEx ); it does not work anymore.
I have checked that the path is correct with:
file_exists( $phpbb_root_path . "common." . $phpEx )
and is_readable( $phpbb_root_path . "common." . $phpEx )
and they all return SUCCESS.

Any idea why it does not work? What do I need to do to access phpBB functions?
:?:
Thanks in advance
Last edited by potiron on Thu Aug 14, 2014 11:09 am, edited 2 times in total.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Accessing PHPBB via script on a sub-domain - import user

Post by Brf »

You cannot put the phpBB stuff in a function like that without globalizing all of the objects. it is normally in the top-level program, so all of the objects are globalized by default.
potiron
Registered User
Posts: 61
Joined: Wed Dec 01, 2004 9:55 am

Re: Accessing PHPBB via script on a sub-domain - import user

Post by potiron »

Indeed, thanks for the response.

When I added the necessary variables as global, it worked. See the beginning of the code:

Code: Select all

function importPhpBB($user_detail)
{
	define('IN_PHPBB',true);
	/* set scope for variables required later */
	global $phpbb_root_path;
	global $phpEx;
	global $db;
	global $config;
	global $user;
	global $auth;
	global $cache;
	global $template;
	
	$phpbb_root_path = "/home/example/forums/";
	$phpEx = substr(strrchr(__FILE__, '.'), 1);

	require_once( $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();
Locked

Return to “[3.0.x] MOD Writers Discussion”