LDAP - List groups
You need to actually pass the search to it. Currently you are using:
$filter ="(ou=*)";
This will need to change to contain 'Students'. While I am no LDAP expert, I would guess at the following:
$filter ="(cn=Students)";
Most of the LDAP stuff I have done has been sheer trial and error rather than knowing what I am doing, but this might put you on the right path.
There is also a Microsoft plugin - Active Directory Explorer you can use to at least browse the LDAP so that you know what to search for and under what branch.
Comments
-
IlludiumPu36 almost 2 years
I need to list all groups within a certain group using PHP. This is what I have so far:
<?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,"[email protected]","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 />'; } ?>
This returns a list of groups, one of whch is 'Students', but I want to list all groups within 'Students'. How can I do this?
EDIT
Thanks to Fluffeh the Microsoft LDAP plugin allows me to search active directorys so I can tailor my PHP script accordingly,
e.g. $ldap_dn = "ou=Units,ou=Groups,dc=somewhere,dc=somewher,dc=somewhere,dc=au";
So my mostly working code is:
<?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,"[email protected]","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 />'; } ?>
-
IlludiumPu36 over 10 yearsThanks Fluffeh, changing the filter didn't do much, but I like your suggestion of the plugin. That's very helpful!
-
Fluffeh over 10 years@PeterBrowne Using that plugin and sheer trial and error was the only way I got my (simple) script up and running. It worked out, but I wouldn't say I totally understand every bit of the code and how it works :)