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

时间:2015-10-14 13:12:20

标签: php active-directory ldap

我正在尝试使用LDAP查询和PHP从AD中获取信息。下面是我的代码,似乎没有从此代码返回任何内容。我在if(TRUE === $ bind)中遇到代码块问题。有人帮我指出错误吗?

这是用于列出AD中所有用户并在WordPress页面上显示的PHP代码。

$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 />";
}

这是页面上显示的内容

连接成功
绑定成功
检索...
你好
取消绑定已完成

由于

0 个答案:

没有答案