phpBB

Development Wiki

Difference between revisions of "Add users"

From phpBB Development Wiki

(Syntax error fixed, changed actkey example to pick a random length of ~10 instead of ~8)
m (Usage)
Line 3: Line 3:
 
==Usage==
 
==Usage==
 
<php>user_add($user_row, $cp_data = false)</php>
 
<php>user_add($user_row, $cp_data = false)</php>
First arguement '''$user_row''' array<br>
+
First argument '''$user_row''' array<br>
Second (optional) arguement '''$cp_data''' array<br>
+
Second (optional) argument '''$cp_data''' array<br>
 
Required values of '''$user_row''': username, password, group_id, user_email, user_type<br>
 
Required values of '''$user_row''': username, password, group_id, user_email, user_type<br>
 
All other fields are optional.<br><br>
 
All other fields are optional.<br><br>
Line 31: Line 31:
 
</php>
 
</php>
 
<br><br>
 
<br><br>
 +
 
==Breakdown==
 
==Breakdown==
 
Following is a detailed breakdown of each item used in creating a new user.<br>
 
Following is a detailed breakdown of each item used in creating a new user.<br>

Revision as of 03:15, 23 November 2008

Adding users to phpBB3 is a fairly simple process.
Made all the more simple by the built in user_add(); function.

Usage

user_add($user_row$cp_data false)

First argument $user_row array
Second (optional) argument $cp_data array
Required values of $user_row: username, password, group_id, user_email, user_type
All other fields are optional.

Following is a simple example of how to add a new user to the phpBB3 database.

$user_row = array(
    
'username'              => $username,
    
'user_password'         => phpbb_hash($password),
    
'user_email'            => $email_address,
    
'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_ip'               => $user_ip,
    
'user_regdate'          => $registration_time,
    
'user_inactive_reason'  => $user_inactive_reason,
    
'user_inactive_time'    => $user_inactive_time,
);

// all the information has been compiled, add the user
// tables affected: users table, profile_fields_data table, groups table, and config table.
$user_id user_add($user_row);



Breakdown

Following is a detailed breakdown of each item used in creating a new user.

This article is a stub. You can help in improving Olympus Documentation by expanding it.


-- Needs CP info before this article is complete

// username of the user being added
$username 'Highway of Life';

// the user’s password, which is hashed before inserting into the database
$password 'MyCoMpLeX_PaSsWoRd';

// an email address for the user
$email_address 'my_email@domain_name.tld';

// default is 4 for registered users, or 5 for coppa users.
$group_id = ($coppa) ? 4;
// since group IDs may change, you may want to use a query to make sure you are grabbing the right default group...
$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);
$row $db->sql_fetchrow($result);
$group_id $row['group_id'];

// timezone of the user... Based on GMT in the format of '-6', '-4', 3, 9 etc...
$timezone '-6';

// two digit default language for this use of a language pack that is installed on the board.
$language 'en';

// user type, this is USER_INACTIVE, or USER_NORMAL depending on if the user needs to activate himself, or does not.
// on registration, if the user must click the activation link in their email to activate their account, their account
// is set to USER_INACTIVE until they are activated. If they are activated instantly, they would be USER_NORMAL
$user_type USER_INACTIVE;

// here if the user is inactive and needs to activate thier account through an activation link sent in an email
// we need to set the activation key for the user... (the goal is to get it about 10 chars of randomization)
// you can use any randomization method you want, for this example, I’ll use the following...
$user_actkey md5(rand(0100) . time());
$user_actkey substr($user_actkey0rand(812));

// IP address of the user stored in the Database.
$user_ip $user->ip;

// registration time of the user, timestamp format.
$registration_time time();

// inactive reason is the string given in the inactive users list in the ACP.
// there are four options: INACTIVE_REGISTER, INACTIVE_PROFILE, INACTIVE_MANUAL and INACTIVE_REMIND
// you do not need this if the user is not going to be inactive
// more can be read on this in the inactive users section
$user_inactive_reason INACTIVE_REGISTER;

// time since the user is inactive. timestamp.
$user_inactive_time time();

// these are just examples and some sample (common) data when creating a new user.
// you can include any information 
$user_row = array(
    
'username'              => $username,
    
'user_password'         => phpbb_hash($password),
    
'user_email'            => $email_address,
    
'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_ip'               => $user_ip,
    
'user_regdate'          => $registration_time,
    
'user_inactive_reason'  => $user_inactive_reason,
    
'user_inactive_time'    => $user_inactive_time,
);

// Custom Profile fields, this will be covered in another article.
// for now this is just a stub
// all the information has been compiled, add the user
// the user_add() function will automatically add the user to the correct groups
// and adding the appropriate database entries for this user...
// tables affected: users table, profile_fields_data table, groups table, and config table.
$user_id user_add($user_row);


See Also