duanguai2781 2015-10-14 13:12
浏览 324

LDAP查询字符串从AD获取信息

I am trying to get information out of AD using LDAP query and PHP. Below is my code and it seems like nothing returns from this code. I have an issue with code block in if (TRUE === $bind). Would anyone help me to point out the error?

This is php code for listing all users in AD and showing up on WordPress page.

$ldap_password = "pass";
$ldap_username = "username";
$person = "Scott";

$ldap_connection = ldap_connect("host1");
if (FALSE === $ldap_connection) { 
    echo "Connection is failed<br />";
}
else {
    echo "Connection is successful<br />";  
}

ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die("Unable to set LDAP protocol version");
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); 

$bind = ldap_bind($ldap_connection, $ldap_username, $ldap_password);
if (TRUE === $bind) {echo "Binding is successful<br />";}
else {echo "Binding is unsuccessful<br />";}

if (TRUE === $bind) {
    echo "Retrieving...<br />";
        $baseDN = "dc=domain,dc=com";
        $filter="(|(sn=$person*)(givenname=$person*))";
        $justthese = array("ou");
        $sr = ldap_list($ldap_connection, $baseDN, $filter, $justhese);
        $info = ldap_get_entries($ldap_connection,$sr);
        echo $info["count"]."Hello<br />";
        for ($i=0; $i < $info["count"]; $i++) {
            echo $info[$i]["ou"][0];
        }
    ldap_unbind($ldap_connection);
    echo "Unbinding is completed<br />";
}

This is what shows up on the page

Connection is successful
Binding is successful
Retrieving…
Hello
Unbinding is completed

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog