PHP LDAP 获取“Office”来自 Active Directory 的字段
我将在公司门户网站中实施 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绑定成功后,您需要执行 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.