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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度