PHP LDAP 获取“Office”来自 Active Directory 的字段

发布于 2024-12-13 14:38:00 字数 758 浏览 1 评论 0原文

我将在公司门户网站中实施 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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰ゝ天使的微笑 2024-12-20 14:38:00

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文