User Register From External Script

Discussion forum for MOD Writers regarding MOD Development.
Locked
KyleCoder
Registered User
Posts: 1
Joined: Sat Jan 10, 2015 3:19 am

User Register From External Script

Post by KyleCoder » Sat Jan 10, 2015 3:26 am

Hey Folks,

I have been searching on getting users registered in phpBB from a external script, and I ran into an error. I may be missing something. I'll paste the code here.

Code: Select all

<?php
define('IN_PHPBB', true);
global $db;
global $config;
global $user;
global $auth;
global $cache;
global $template;
global $phpbb_root_path;
global $phpEx;

$phpbb_root_path = '../phpbb/';  // forum directory path here
$phpEx = 'php';
//include($phpbb_root_path . 'common.' . $phpEx);

include($phpbb_root_path.'common.php');

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

require($phpbb_root_path .'includes/functions_user.php');

$username = 'MyUserName';
$password = 'MyPassword'; // Dont encrypt the password!
$email = 'my@email.com';

// Check for unique username otherwise it will throw an error or might be blank page

$user_row = array(
'username' => $username,
'user_password' => md5($password),
'user_email' => $email,
'group_id' => 2, #Registered users group
'user_timezone' => '1.00',
'user_dst' => 0,
'user_lang' => 'en',
'user_type' => '0',
'user_actkey' => '',
'user_dateformat' => 'd M Y H:i',
'user_style' => 1,
'user_regdate' => time(),
);
$phpbb_user_id = user_add($user_row);
?>
When I execute the following code above, the error was outputted...

Fatal error: Call to a member function header() on a non-object in /var/host/public_html/54789541/phpbb/phpbb/session.php on line 224

Any ideas why this error is being outputted?

Thanks!

usamahateeq
Registered User
Posts: 1
Joined: Wed Jan 21, 2015 7:04 am

Re: User Register From External Script

Post by usamahateeq » Wed Jan 21, 2015 7:10 am

I was having the same problem. After bit of searching and doing some r n d on my own. This is what i did to fix it.

In your page add the line
global $request;


It gave me some more errors so in the end and hit and trial i had to add these following lines to make it work.
global $phpbb_container;
global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;
global $request;
global $phpbb_dispatcher;
global $symfony_request;
global $phpbb_filesystem;

Adding these globals initializes the objects whose functions are being called.

After that i was able to work with the code. Hope that helps

Locked

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