PHP LDAP从Active Directory获取“Office”字段

时间:2011-11-04 16:00:33

标签: php active-directory ldap

我将在公司门户网站中实施LDAP身份验证。登录后,我需要检索用户在Active Directory中“Office”字段(常规选项卡下)中的值。任何帮助将不胜感激。

以下是我的LDAP身份验证代码供参考:

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 个答案:

答案 0 :(得分:0)

绑定成功后,您需要执行ldap_search,然后执行ldap_get_entries。您应该在上述链接中找到大量示例。