Does not work.
The first script causes this errors:
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3858: Cannot modify header information - headers already sent by (output started at /includes/auth/auth_extdb.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3860: Cannot modify header information - headers already sent by (output started at /includes/auth/auth_extdb.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3861: Cannot modify header information - headers already sent by (output started at /includes/auth/auth_extdb.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3862: Cannot modify header information - headers already sent by (output started at /includes/auth/auth_extdb.php:1)
And I don't know how to choose the table "account" from the realmd db...
Please help!
/edit:
Here's my extdb code. Database passwords are changed
<?php
/**
* External Database auth plugin for phpBB3
* Based on phpbb's ldap auth plugin.
* Pedro Dias - [email]
[email protected][/email]
* [url]http://pedrodiasgeekyblog.blogspot.com/2008/11/external-database-authentication-for.html[/url]
*/
/*
Credit goes to Pedro for posting the example on his blog. I made some changes to the script,
since I was getting a connections error. The changes I made will help people who install
phpbb3 into its own separate database.
I can assist with some help pm acctman on phpbb3
p.s. I am not Pedro, I'm just giving him credit for his work. I modified the script to make
it work better.
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
function login_extdb(&$username, &$password)
{
global $db, $config, $user;
if (!$password)
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'NO_PASSWORD_SUPPLIED',
'user_row' => array('user_id' => ANONYMOUS),
);
}
if (!$username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
//// START HERE //// change where you see FILL IN
/// This is the connection for my existing member database
$dbhost1 = 'localhost';
$dbuser1 = 'root'; //this is the mysql login for your existing member db
$dbpass1 = 'DaTaBaSePaSsWoRd';
$dbname1 = 'realmd';
$conn = mysql_connect($dbhost1, $dbuser1, $dbpass1) or die ('Error connecting to mysql');
mysql_select_db($dbname1);
// We need to select the required fields, check you member table and write down the
// following USERNAME, PASSWORD, EMAIL field names. Example my existing member fields are called
// m_user, m_pass and m_email yours will be different. If you're lazy you can also do a SELECT *
// I would replace with SELECT m_user, m_pass, m_email
// This is how my query looks:
// $query = "SELECT m_user,m_pass,m_email FROM rate_members WHERE m_user = '".$username."'";
$query = "SELECT username,sha_pass_hash,email FROM account WHERE username = '".$username."'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows == 1){
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$extuser = $row['username']; //user field from existing db member table
$extpass = $row['sha_pass_hash']; //pass field from existing db member table
$extmail = $row['email']; //email field from existing db member table
}
if ($num_rows == 1)
{
if (strcmp($extuser,$username) == 0 && strcmp($extpass,md5($password)) == 0)
{
/// This is the connection for phpBB3's database. The next 6 lines can be removed only if you've installed phpBB3 into you existing site db.
/// I decided to keep things separate to make it easier to backup/restore.
$dbhost = 'localhost';
$dbuser = 'root'; // you can get the info from the config.php file in your forum root
$dbpass = 'DaTaBaSePaSsWoRd';
$dbname = 'forum';
//// END HERE //// you do not have to change anything else for the script to work
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_type
FROM phpbb_users' . "
WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row)
{
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
{
return array(
'status' => LOGIN_ERROR_ACTIVE,
'error_msg' => 'ACTIVE_ERROR',
'user_row' => $row,
);
}
return array(
'status' => LOGIN_SUCCESS,
'error_msg' => false,
'user_row' => $row,
);
}
else
{
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
AND group_type = " . GROUP_SPECIAL;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row)
{
trigger_error('NO_GROUP');
}
$extdb_user_row = array(
'username' => $username,
'user_password' => phpbb_hash($password),
'user_email' => $extmail,
'group_id' => (int) $row['group_id'],
'user_type' => USER_NORMAL,
'user_ip' => $user->ip,
);
return array(
'status' => LOGIN_SUCCESS_CREATE_PROFILE,
'error_msg' => false,
'user_row' => $extdb_user_row,
);
}
}
else
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'LOGIN_ERROR_PASSWORD',
'user_row' => array('user_id' => ANONYMOUS),
);
}
}
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}
?>