我正在嘗試創建一個PHP腳本,它將返回屬於Active Directory中特定組的一部分的每個成員的一些詳細信息。PHP LDAP獲取作爲組成員的成員的用戶詳細信息
我沒有任何問題連接並顯示組成員的姓名(CN),但是當涉及顯示諸如電話,電子郵件和用戶名等詳細信息時,我被卡住了。
這是我正在嘗試的代碼。任何人都可以看到我做錯了什麼?
<?php
$ldap_server = "AD_Server.domain.pri:389";
$auth_user = "[email protected]";
$auth_pass = "password";
$base_dn = "OU=IM Groups,OU=GLOBAL,DC=domain,DC=pri";
$filter = "(&(objectCategory=user)(memberOf=IM-ALL_USERS))";
// connect to server
if (!([email protected]_connect($ldap_server))) {
die("Could not connect to ldap server");
}
// bind to server
if (!($bind = ldap_bind($connect, $auth_user, $auth_pass))) {
die("Unable to bind to server");
}
// search active directory
if (!($search = ldap_search($connect, $base_dn, $filter))) {
die("Unable to search ldap server");
}
$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);
echo "The number of entries returned is ". $number_returned."<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "Name is: ". $info[$i]["givenname"][0]."<br>";
echo "Display name is: ". $info[$i]["displayname"][0]."<br>";
echo "Email is: ". $info[$i]["mail"][0]."<br>";
echo "Telephone number is: ". $info[$i]["telephonenumber"][0]."<p>";
}
?>
你試過用print_r/vardump傾出'$ info'數組來看看裏面有什麼嗎? – 2011-03-16 15:05:35
$ info數組只包含「Array([count] => 0)」,因此它看起來像腳本對篩選器不滿意。 – Brigante 2011-03-16 15:09:38