简体   繁体   English

PHP将ldap绑定到活动目录

[英]php bind ldap to active directory

In PHP, how can you bind using a property other than the default cn? 在PHP中,如何使用默认cn以外的属性进行绑定? (I'm not asking how to validate a user account using LDAP search queries, I'm specifically asking how I can bind using a sAMAaccountname and password in PHP). (我不是在问如何使用LDAP搜索查询来验证用户帐户,我是在问如何在PHP中使用sAMAaccountname和密码进行绑定)。

In Perl, this is possible by specifying the property to query directly on the LDAP string: 在Perl中,可以通过指定直接在LDAP字符串上查询的属性来实现:

ldap://ldap.example.com/dc=example,dc=com?sAMAccountName 

The php ldap_connect funciton only takes a server name so these additional parameters are not able to be passed. php ldap_connect函数仅使用服务器名称,因此无法传递这些附加参数。 Also the bind function only takes a connection, username, and password. 同样,bind函数仅接受连接,用户名和密码。

Connect simply opens the connection it doesn't set any credentials on the connection. Connect只是打开连接而未在连接上设置任何凭据。 Once the connection is open you bind it to a set of credentials using ldap_bind . 打开连接后,您可以使用ldap_bind将其绑定到一组凭据。

In connecting to AD you can use 3 different formats for the username. 在连接到AD时,您可以为用户名使用3种不同的格式。

  1. The DN. DN。
  2. The samAccountName which may or may not need the domain prefixed in it as Domain\\samAccountName . samAccountName可能需要也可能不需要以Domain\\samAccountName作为前缀的Domain\\samAccountName
  3. The user principal name which has a format that looks similar to an email address. 用户主体名称,其格式类似于电子邮件地址。

I have used adLDAP in the past and it's worked incredibly well. 我过去曾经使用过adLDAP ,而且效果非常好。 If you choose not to use that script, it should at least point you in the correct direction (ahh, the joys of open source). 如果您选择不使用该脚本,那么它至少应将您指向正确的方向(啊,开放源码的乐趣)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM