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 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器