ldap_search returns 空数组

ldap_search returns empty array

我放弃了:(

在 ubuntu 中使用 ldapsearch:

ldapsearch -x -LLL -h xx.xxxx.xx:3268 -D login -w password -b "DC=uni-xx,DC=xx" -v -s sub "userprincipalname=xx8870@student.xxx.xx"

returns 此用户的正确信息。

移动到同一服务器上的 php:

if (($connect = ldap_connect($ldap_server, $obj->port))) {

ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $obj->LDAP_OPT_PROTOCOL_VERSION);          

$dn = $obj->contexts; //"DC=uni-xx,DC=xx"
$bu = $obj->bind_user; //login
$bp = $obj->bind_pw; //password
$bind = ldap_bind($connect, $bu, $bp); 

if($bind){

    $is_tu_user = ldap_search($connect, $dn, "(userprincipalname=*xx8870*)", array("cn", "mail"));
    echo ldap_error($connect);
    $info = ldap_get_entries($connect, $is_tu_user);
    print_r(" sss " . json_encode($info));die();
    }
}

returns 具有零个元素的数组:

{"count":0}

PHP 是 7.2 版。 LDAP 扩展已启动并且 运行.

终于找到了罪魁祸首:在 PHP 代码中,我将我的服务器地址提供为 "ldap://xx.xxxx.xx",我猜这是不正确的方式。我没有在 unix shell 命令中使用协议。

您必须使用 ldap_connect("xx.xxxx.xx", 3268),没有协议,才能在子树 od (Microsoft?) AD 中搜索服务器。