Insert a user into phpBB from PHP

Discussion forum for MOD Writers regarding MOD Development.
cybz
Registered User
Posts: 3
Joined: Fri Nov 14, 2008 8:47 pm

Re: Insert a user into phpBB from PHP

Post by cybz »

I'm using a class i found pretty useful, it has some problems, but i fixed them and you can customize it to do what you want pretty easily.

http://www.phpclasses.org/browse/package/4826.html
User avatar
3Di
Former Team Member
Posts: 15886
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Insert a user into phpBB from PHP

Post by 3Di »

care to share your fixes? :)
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
cybz
Registered User
Posts: 3
Joined: Fri Nov 14, 2008 8:47 pm

Re: Insert a user into phpBB from PHP

Post by cybz »

Check in the support forum of that class they are in there
User avatar
3Di
Former Team Member
Posts: 15886
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Insert a user into phpBB from PHP

Post by 3Di »

A link would have been appreciated instead. Thanks anyway.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
purewishes
Registered User
Posts: 2
Joined: Thu Jun 18, 2009 8:35 am

Re: Insert a user into phpBB from PHP

Post by purewishes »

Hi everyone,

I'm new here , and also in phpbb3,
I sucsessfully installed my phpbb3 forum,
and i have a the same thing in getting users from my site,
I need my site contains the same registration form in the forum,
and then after registering; i need users registered in my site, automatically added to user database in forum.
I see here different codes, and i'm getting dispersed,
My questions are:
- which files to edit?
- which codes to insert?
- where to insert?
- which file contains the registration form (in oreder to use it in my site)
..
sorry for my english, and for my fuzzy
question..
..
Thanks for your help :)
ctrader
Registered User
Posts: 6
Joined: Wed Jun 17, 2009 7:37 pm

Re: Insert a user into phpBB from PHP

Post by ctrader »

Hi All,

I am adding users to my phpbb3.0.4 database and all seems to work ie member exist in phpbb and they can login.
BUT when they login they can't see any forums, I found it is a member but no group is actualy assigned in ACP, adding the imported user manualy via ACP to registered users solves this problem. My code inserts the user with a group_id2 which is registerd users, I can also see this in the db. Why is the user not in the group when viewing via ACP?

Best regards
User avatar
Kellanved
Former Team Member
Posts: 2635
Joined: Wed Jan 26, 2005 2:48 pm
Location: Meta-level

Re: Insert a user into phpBB from PHP

Post by Kellanved »

Just inserting users into the database will not work, as user accounts are spread out over several tables. The way to add users in a script is using the user_add API function, the CSV importer or one of the other user account creation MODs.
Nocando is in Idontwanna county. No support via PM
beyondflash
Registered User
Posts: 15
Joined: Mon Apr 27, 2009 1:18 pm

Re: Insert a user into phpBB from PHP

Post by beyondflash »

I am trying to use the user_add() function...everytime I attempt to call that function all I get is a blank page.
Here is the code I am using:

Code: Select all

function register_phpBB($username,$user_password,$user_email){
//fucntion to regiter with phpBB
    
define('IN_PHPBB', true);
$phpbb_root_path = 'forum/';

//$phpEx = substr(strrchr(__FILE__, '.'), 1);
include('forum/common.php');
include('forum/includes/functions_user.php');
include('forum/includes/ucp/ucp_register.php');

$password=$user_password;
$username=$username;
$username_clean=strtolower($username);
$user_email=$user_email;

    $sql_ary = array(
        'username'          => $username,
        'username_clean'    => $username_clean,
        'user_password'     => phpbb_hash($password),
        'user_pass_convert' => 0,
        'user_email'        => $user_email,
        'user_email_hash'   => crc32(strtolower($user_email)) . strlen($user_email),
        'group_id'          => 2,
        'user_type'         => 0,
    );
user_add($sql_ary);
what am I missing here?
ctrader
Registered User
Posts: 6
Joined: Wed Jun 17, 2009 7:37 pm

Re: Insert a user into phpBB from PHP

Post by ctrader »

Kellanved wrote:Just inserting users into the database will not work, as user accounts are spread out over several tables. The way to add users in a script is using the user_add API function, the CSV importer or one of the other user account creation MODs.
My existing code was like this

Code: Select all

// OK, insert/update this stuff into phpBB3 user table
if ($new_registration) {    // on register
  mysql_query("INSERT INTO `phpbb3_users` SET 
  user_pass_convert=1, 
  user_type=0, 
  group_id=2, 
  username='$user_details[username]', 
  username_clean='".strtolower($user_details[username])."', 
  user_password='$bb3_passwd', 
  user_email='$bb3_email', 
  user_email_hash='$bb3_hash', 
  user_regdate='".CURRENT_TIME."', 
  user_from='$user_details[city] ($user_details[state]) $country[name]' ") 
  or die(mysql_error());
Is it possible to replace the above with the "user_add", meaning should it work, same type code ?
purewishes
Registered User
Posts: 2
Joined: Thu Jun 18, 2009 8:35 am

Re: Insert a user into phpBB from PHP

Post by purewishes »

I'm sorry for bothering ..
but i really need answers of my questions.
so, any one can help please..?
..
Thanks in advance.
User avatar
joeroberts
Registered User
Posts: 272
Joined: Fri Jun 22, 2007 7:19 pm
Contact:

Re: Insert a user into phpBB from PHP

Post by joeroberts »

Now I know I have posted this Many Many time but here it is again

Code: Select all

function forumadd($username){//forumadd(the users name)
//global $db, $forumpx, $db_prefix, $forumbase, $phpEx, $config,$phpbb_root_path;
define('FORUM_ADD',TRUE);
define('phpBBBASE',$forumbase);
define("PHPBB_ROOT_PATH","(setyourpath)");//change this to your forum root path **./forum**
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
include_once($phpbb_root_path. '/common.'.$phpEx);
include_once($phpbb_root_path . '/includes/functions_user.' . $phpEx);
global $config;
define('IN_PHPBB',TRUE);
define('IN_PORTAL',TRUE);
        $coppa            = (isset($_REQUEST['coppa'])) ? ((!empty($_REQUEST['coppa'])) ? 1 : 0) : false;
        $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
        $sql = 'SELECT group_id
        FROM ' . GROUPS_TABLE . "
        WHERE group_name = '" . $db->sql_escape($group_name) . "'
            AND group_type = " . GROUP_SPECIAL;
$result = $db->sql_query($sql)or print(mysql_error());
$row = $db->sql_fetchrow($result);
$group_id = $row['group_id'];
$res = "SELECT id,username,password,email FROM ".$db_prefix."_users WHERE username ='".escape($username)."';";//change ".$db_prefix."_users to match your users data base table
$result = $db->sql_query($res)or print(mysql_error());
$user_actkey = md5(rand(0, 100) . time());
$user_actkey = substr($user_actkey, 0, rand(6, 10));
$timezone = '-6';
$language = 'en';
$user_type = USER_NORMAL;
$is_dst = date('I');
        $arr = $db->sql_fetchrow($result);
                $user_row = array(
                    'username'                => $arr['username'],
                    'user_password'            => $arr['password'],
                    'user_email'            => $arr['email'],
                    'group_id'                => (int) $group_id,
                    'user_timezone'            => (float) $timezone,
                    'user_dst'                => $is_dst,
                    'user_lang'                => $language,
                    'user_type'                => $user_type,
                    'user_actkey'            => $user_actkey,
                    'user_regdate'            => time(),
                );

                // Register user...
                 user_add($user_row);
}
 
this is the code that I use In My phpMyBitTorrent integration with phpBB3 It works 100%
and this

Code: Select all

                                                                                                       $autologin =true;//set to false for no auto login
                                                    if($level === 'admin')$admin = 1;
                                                    else
                                                    $admin = 0;
                                             define( 'IN_PHPBB', true );
                                             $phpbb_root_path = './'.$forumbase . '/'; 
                                                $phpEx = substr(strrchr(__FILE__, '.'), 1);
                                                include($forumbase . '/common.' . $phpEx);
                                               include($forumbase . '/includes/functions_display.' . $phpEx);
                                             include($forumbase . '/includes/bbcode.' . $phpEx);
    
                                                $user->session_begin();
                                                $auth->acl( $user->data );
                                                $user->setup();
                                                $user->session_create($_POST['username'], $admin, $autologin, 1);//$_POST['username'] needs to be the forum Id for the user I use a function to get this
 
is My login
Both of these codes uses phpBB3's own codes to create the account and to login the user please make sure you see all comments in the code they well tell you what to change 8-) Hope this well help you along your way
lenamson
Registered User
Posts: 2
Joined: Thu Aug 20, 2009 12:18 pm

Re: Insert a user into phpBB from PHP

Post by lenamson »

I have a problem:
How to change password automatic?

my users change password with other Interface, not of PHPBB

So I need more: script to change password automatic!

Thanks!
lenamson
Registered User
Posts: 2
Joined: Thu Aug 20, 2009 12:18 pm

Re: Insert a user into phpBB from PHP

Post by lenamson »

And I have more problem:
- With this script of creating user, mail notice is not send to User?
User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Re: Insert a user into phpBB from PHP

Post by D¡cky »

lenamson,

There is a tool for importing users if you can get the users into a CSV file format, Import Users.

This tool will set the passwords correctly for phpBB3 and send out an email to users if you select that option.
Have you hugged someone today?
User avatar
illonavamp
Registered User
Posts: 14
Joined: Mon Nov 12, 2007 12:19 pm
Location: England
Contact:

Re: Insert a user into phpBB from PHP

Post by illonavamp »

I have managed to migrate my users from my old phpbb into my new one - via other means.

However, none of them have their email_hash generated - it's 0 for all the users I've migrated across.

Is there a way of generating this? I did see this somewhere -

Code: Select all

'user_email_hash'   => crc32(strtolower($user_email)) . strlen($user_email),
- was wondering is anyone was cleaver enough to chuck a script together for me that will do this or whether there's some other option. I've about 500 users.

TY muchly,

Sam
Locked

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