0
votes

I will be implementing LDAP authentication into a company web portal. Once they login, I need to retrieve the value that user has in the "Office" field (under the general tab) in Active Directory. Any help would be greatly appreciated.

Here is my LDAP authentication code for reference:

public function ldap_authentication($username, $password) {
    $connection = ldap_connect($this->HOST, $this->PORT) or die("Can't establish LDAP connection");
    ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

    if ($connection) {
        $bind = ldap_bind($connection, $username.$this->DOMAIN, $password) or die("Can't bind to LDAP");
        if ($bind) {
            $authenticated = true;
        } 
        else {
            $authenticated = false;
        }
    }
    else {
        $authenticated = false;
    }
    ldap_unbind($connection);
    return $authenticated;
}
1
You may want to try implementing adldap.sourceforge.net that simplifies a lot interacting with AD. - dev-null-dweller

1 Answers

0
votes

Once your bind is successful, you need to do an ldap_search, followed by ldap_get_entries. You should find plenty of examples at the aforementioned links.