[英]LDAP - List groups
我需要使用PHP列出某個組中的所有組。 這是我到目前為止的內容:
<?php
$ldap_dn = "ou=People,dc=something,dc=something,dc=something,dc=au";
$ldap_svr = "ldap.server.somewhere";
$ldap_domain = "domain.somewhere";
$conn=ldap_connect($ldap_svr) or die("Cannot connect to LDAP server!");
ldap_set_option ($conn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($conn,"user@domain.somewhere","password");
$filter ="(ou=*)";
$justthese = array("ou");
$result=ldap_list($conn, $ldap_dn, $filter, $justthese) or die("No search data found.");
$info = ldap_get_entries($conn, $result);
for ($i=0; $i < $info["count"]; $i++) {
echo $info[$i]["ou"][0] . '<br />';
}
?>
這將返回一組列表,其中之一是“學生”,但我想列出“學生”中的所有組。 我怎樣才能做到這一點?
編輯
多虧了Fluffeh,Microsoft LDAP插件允許我搜索活動目錄,因此我可以相應地調整PHP腳本, eg $ldap_dn = "ou=Units,ou=Groups,dc=somewhere,dc=somewher,dc=somewhere,dc=au";
所以我最有效的代碼是:
<?php
$ldap_dn = "ou=Units,ou=Groups,dc=somewhere,dc=somewher,dc=somewhere,dc=au";
$ldap_svr = "ldap.server.somewhere";
$ldap_domain = "domain.somewhere";
$conn=ldap_connect($ldap_svr) or die("Cannot connect to LDAP server!");
ldap_set_option ($conn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($conn,"user@domain.somewhere","password");
$filter ="(cn=*)";
$justthese = array('cn');
$result=ldap_list($conn, $ldap_dn, $filter, $justthese) or die("No search data found.");
$info = ldap_get_entries($conn, $result);
for ($i=0; $i < $info["count"]; $i++) {
echo $info[$i]["cn"][0] . '<br />';
}
?>
您實際上需要將搜索傳遞給它。 當前您正在使用:
$filter ="(ou=*)";
這將需要更改以包含“學生”。 雖然我不是LDAP專家,但我會猜測以下幾點:
$filter ="(cn=Students)";
我所做的大多數LDAP工作都是經過反復試驗而不是知道我在做什么,但這可能使您走上正確的道路。
還有一個Microsoft插件-Active Directory Explorer ,可用於至少瀏覽LDAP,以便您知道要搜索的內容以及在哪個分支下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.