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.

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

报告相同问题?

悬赏问题

  • ¥60 如何批量获取json的url
  • ¥15 对法兰连接元件所承受的表面载荷等效转化为法兰开孔接触面上的等效表面载荷?
  • ¥15 comsol仿真压阻传感器
  • ¥15 Python线性规划函数optimize.linprog求解为整数
  • ¥15 llama3中文版微调
  • ¥15 pg数据库导入数据序列重复
  • ¥15 三分类机器学习模型可视化分析
  • ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
  • ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
  • ¥30 python,LLM 文本提炼