dqwh1209 2019-01-25 14:27
浏览 147
已采纳

ldap_search返回空数组

I give up :(

Using ldapsearch in ubuntu:

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 correct informations for this user.

Moving to php on the same server:

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 array with zero elements:

{"count":0}

PHP is version 7.2. LDAP extension is up and running.

  • 写回答

1条回答 默认 最新

  • dongyun6003 2019-01-28 09:14
    关注

    Finally found the culprit: in PHP code, I supplied my server address as "ldap://xx.xxxx.xx" which I guess its incorrect way. I didnt use protocol in unix shell command.

    You have to use ldap_connect("xx.xxxx.xx", 3268), without protocol, to be able to search in subtrees od (Microsoft?) AD server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 Qt 不小心删除了自带的类,该怎么办
    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!