Articles index » phpBB 3.0 » Create a new user

Create a new user

Create a new user in phpBB 3.0.

Submitted by eviL<3 on 11 Jan 2008, 16:50

phpBB 3.0 offers functions to manage users, these include user_ban, user_delete, user_unban, user_update_name. The one we'll need is user_add. These user-related functions can be found in includes/functions_user.php.

The arguments

$user_row is an array of user data. Following keys are required: username, user_password, user_email, group_id, user_type. Following keys are optional, and most of them will never be needed anyway: user_permissions, user_timezone, user_dateformat, user_lang, user_style, user_allow_pm, user_actkey, user_ip, user_regdate, user_passchg, user_options, user_inactive_reason, user_inactive_time, user_lastmark, user_lastvisit, user_lastpost_time, user_lastpage, user_posts, user_dst, user_colour, user_occ, user_interests, user_avatar, user_avatar_type, user_avatar_width, user_avatar_height, user_new_privmsg, user_unread_privmsg, user_last_privmsg, user_message_rules, user_full_folder, user_emailtime, user_notify, user_notify_pm, user_notify_type, user_allow_pm, user_allow_viewonline, user_allow_viewemail, user_allow_massemail, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield, user_form_salt.

$cp_data is either false (by default), or an array of custom profile data, the keys are the cpf's field_ident, the value is the value.

The return value

The value returned by the function is the new user's user_id.

An example

An example of how to use the function:

Code: Select all
// select the group_id
$sql = 'SELECT group_id
   FROM ' . GROUPS_TABLE . "
   WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
      AND group_type = " . GROUP_SPECIAL;
$result = $db->sql_query($sql);
$group_id = (int) $db->sql_fetchfield('group_id');
$db->sql_freeresult($result);

// set user data
$user_row = array(
   'username'         => 'evil&lt;3',
   'user_password'      => 'a_cheap_pass',
   'user_email'      => 'evil@somesite.com',
   'group_id'         => $group_id,
   'user_type'         => USER_NORMAL,
);

// add user
$user_id = user_add($user_row);
 

License:

All articles in the knowledge base are licensed under the phpbbmodders beerware-nc license.

Back to category


Articles index » phpBB 3.0 » Create a new user