Username and LDAP (Alternative Username)

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
Registered User
Posts: 5
Joined: Tue Jan 20, 2009 8:15 pm

Re: Username and LDAP (Alternative Username)

Post by masterkeedu »


in includes/function_content

DO NOT make the following edit as it will break the ability to pull users form a search in the admin panel because it will try to use the Real NAme rather than the username. Thus returning a "user Not Found" error.

Code: Select all

    if ($guest_username === false)
            $sql = "SELECT * FROM `phpbb_users` WHERE `user_id` = '" . $user_id . "'";
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $username = ($row['user_from']) ? $row['user_from'] : $username;
Instead copy the entire function, rename to get_realname_string() and insert back into the class using the code above in place of
$username = ($username) ? $username : $user->lang['GUEST'];

This way the internal workings can still retrieve the physical username when needed, and we can adjust all the outward facing displaying to use Real Name instead without disrupting other features.

To do this you'll need to start hacking away at
index.php, viewforum.php, and viewtopic.php, includes/functions_posting.php

Basically just do a global search on get_username_string(. Look where it is(the context of its use) and change to get_realname_string( as needed.

Example, we'll change the 'newest member' section of index.php that is shown at the foot on the index page

Starting ~ line 115 The NEWEST_USER is the line we care about.

Code: Select all

// Assign index specific vars
	'TOTAL_POSTS'	=> sprintf($user->lang[$l_total_post_s], $total_posts),
	'TOTAL_TOPICS'	=> sprintf($user->lang[$l_total_topic_s], $total_topics),
	'TOTAL_USERS'	=> sprintf($user->lang[$l_total_user_s], $total_users),
	'NEWEST_USER'	=> sprintf($user->lang['NEWEST_USER'], get_realname_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),

	'LEGEND'		=> $legend,

In all I probably had to replace this method call in about 20 places. But to ensure the integrity of the service i think it is worth it.

Registered User
Posts: 2
Joined: Thu Nov 19, 2009 12:57 am

Re: Username and LDAP (Alternative Username)

Post by KhalsaKommander »

My apologies as I'm a novice to both phpBB and php coding in general, but I've tried with no luck to implement the suggestions above.

What I can do is bind to my Active Directory LDAP, and have end users use their userid and password to login. However I cannot get their actual displayname in Active Directory to show as their name once logged in. In Active Directory, I can see that everyone has an item filled out via displayname (their actual first and last name).

When following Paul Manning's instructions above, I get an internal service error. My dB is MySQL and my web server is Apache. I have not reviewed my log files yet as to what the error may be.

When following masterkeedu, I get a MySQL error screen when logging in saying that "user form" cannot be blank.

So in short, has anyone gotten the above to work? If so, can you help me by providing specific instructions on how to go about implementing the above?

I don't think this should be too difficult to implement. Also has anyone gotten this to work by just using the ldap user filter in the client authentication section in the ADP? My team has got a Ruby on Rails application that can grab the displayname from LDAP and I want to implement the same for phpBB.

Thanks in advance for any kind thoughts that may be posted.

Registered User
Posts: 1
Joined: Tue Jul 20, 2010 9:51 pm

Re: Username and LDAP (Alternative Username)

Post by ddenise »

Hi, I want to do a slight variation to this thread here.

My Environment:
LDAP integration to Active Directory

I'd like to:
1)Create a custom profile field called "Full Name"
2)Create a custom script that when authentication happens, pulls displayName from AD and populates the "Full Name" custom field with the displayName value from Active Directory.

I have done the following:
1) Created custom profile field (easy)
2) Created a custom script that will populate the custom profile field based on what username is logging in.

My strategy is to have this file separate and only add the following line to auth.php:

Code: Select all

When I add that line anywhere in auth.php, nothing works, I get just a blank screen. To confirm, yes, when I run the "test.php" it works just great. I also tried just including/requiring a blank .php file and it causes the same problem. Is there something I'm missing about how the php works with PHPBB3?

Registered User
Posts: 1
Joined: Tue Aug 02, 2011 8:50 pm

Re: Username and LDAP (Alternative Username)

Post by jdav »

Dear Masterkeedu,

Thank you very much (and to Paul_manning22) for so good instruction how to get users' Full name from AD to PHPBB.

Everything is working after careful changes on version 3.0.8.

Only one thing is not working after all changes is access to the Client Communication /Authentication (LDAP settings) in the ACP.

After clicking to Authentication receiving "HTTP 500 Internal Server Error", all other tabs is accessible.

Please, help me to resolve this issue.

Registered User
Posts: 7
Joined: Wed Apr 09, 2014 7:44 pm

Re: Username and LDAP (Alternative Username)

Post by Stormy2021 »

Was a proper mod ever written for this? I cant seem to find one for 3.0.12.

MY board is LDAP authenticated. I would really like to have usernames, throughout the entire forum, replaced with Display Names.

In trying to go through the example code in this thread, it appears to be drastically different from the current 3.0.12 code, so I'm pretty much stuck.

* removed *
Last edited by marian0810 on Wed Apr 30, 2014 1:25 pm, edited 1 time in total.
Reason: solicitation removed as per

Registered User
Posts: 1
Joined: Thu Aug 27, 2015 3:12 pm

Re: Username and LDAP (Alternative Username)

Post by JustAskJack »

Was there ever any movement or resolution on this?

I am facing the same issue using 3.1.5 and authenticating with LDAP.

Users log in with their company ID, but we would like for their name to be displayed when they post etc, right now it is displaying their company ID which makes it difficult to determine who is posting.

The steps covered earlier in the thread do not work for the newer versions of phpbb.

Let me know if you can point me in the right direction.

Thank you


Return to “[3.0.x] MOD Requests”