Seite 1 von 1
Benutzer in Datenbank anlegen
Verfasst: 13.01.2012 09:59
von satyria
Hallo,
ich bin zur Zeit dran meine Internetseite mit diesem Forum zu erweitern. Meine Seite hat eine eigene Benutzerverwaltung. Nun würde ich gerne, wenn sich bei mir ein neuer Benutzer anmeldet, diesen auch gleichzeitig in der Forendatenbank anmelden. Welche Werte, welche Datenbankeinträge muss ich dazu ändern/eintragen. Ich habe bereits mal in die Datenbank geschaut. Ist es die Teildatenbank xyz_users, die dafür verantwortlich ist? Wie wird das Password dort verschlüßelt (SHA1...), user_email_hash??? Welche Werte sind Wichtig?
Ich weis, eine Menge Fragen, aber ich würde gerne phpBB benutzen.
Meine Seite läuft auf Basis von PHP5 und MySQL5. Wie ich Eintragungen machen kann, weis ich.
Liebe Grüße, Satyria
Re: Benutzer in Datenbank anlegen
Verfasst: 13.01.2012 10:16
von Dr.Death
Hi,
verwende dazu bitte die phpBB interne Funktion " user_add() ".
Siehe dazu auch:
http://wiki.phpbb.com/Add_users
Code: Alles auswählen
<?php
define('IN_PHPBB', true);
// Specify the path to you phpBB3 installation directory.
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// 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) ? 5 : 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(0, 100) . time());
$user_actkey = substr($user_actkey, 0, rand(8, 12));
// 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);
?>
Re: Benutzer in Datenbank anlegen
Verfasst: 13.01.2012 14:05
von satyria
Danke, für die schnelle Antwort!
Könnte man auch direkt in die Datenbank schreiben, oder könnte sowas Probleme machen?
Re: Benutzer in Datenbank anlegen
Verfasst: 13.01.2012 21:37
von Dr.Death
Einfach nur in die Datenbank zu schreiben ist etwas wenig, außer Du erwischt alle relevanten Tabellen und Felder die für einen User notwendig sein ( User ID, Gruppenzugehörigkeit, Rechtevergabe usw. )
Siehe Dir doch die passende Funktion mal genauer an:
includes /functions_user.php
Code: Alles auswählen
/**
* Adds an user
*
* @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded.
* @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array
* @return the new user's ID.
*/
function user_add($user_row, $cp_data = false)
Gerade die Passwortvergabe ohne die phpbb_hash() Funktion wird etwas schwierig
