Wednesday, 1 June 2011

Adding Users to phpbb forums

So, we have a site that uses the PHPBB forum as a backbone, but we need to add users to it without them going through the normal procedure in the front end:

Here's how

    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 = 'forums/';  // forum directory path here
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    //include($phpbb_root_path . 'common.' . $phpEx);
   
    include('forums/common.php');
   
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
   
    require($phpbb_root_path .'includes/functions_user.php');
   
    $username = $_POST['user'];
    $password = $_POST['password']; // Dont encrypt the password!
    $email = $_POST['email'];
   
    // 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);

No comments:

Post a Comment