AndieB Posted May 16, 2007 Share Posted May 16, 2007 Hi all! I am in need of help and hope that some kind soul out there is able to provide some support. I have managed to connect to Microsoft Active Directory, using PHP and LDAP. Also managed to performe a search in AD for UserAccount information. What I need help with, is to search in AD within an OU (Organizational Unit) and list the reslut into an own array. i.e. In AD the structure looks like this: +Sales -USA -Sweden -Belgium +Finance -Usa -Sweden -Belgium I would like to have them in an array in the format: Sales/USA Sales/Sweden Sales/Belgium Finance/Usa Finance/Sweden Finance/Belgium I would very much appreciate some help! Sincerely, Andreas Link to comment https://forums.phpfreaks.com/topic/51620-php-ldap-list-ous-and-sub-ous/ Share on other sites More sharing options...
hitman6003 Posted May 16, 2007 Share Posted May 16, 2007 Once you query LDAP it returns basically a large multidimensional array that you can then parse through and use the data however you like...put in a new array or what-not... //connect to your ldap server $dn = "ou=sales, DC=USA"; //use your base DN here $filter = "(|(sAMAccountname=*))"; $search_result = ldap_search($ldap_connection, $db, $filter) or die(ldap_error($ldap_connection)); $result = ldap_get_entries($ldap_connection, $search_result); for ($i = 0; $i < $info['count']; $i++) { echo '<pre>' . print_r($info[$i], true) . '</pre><br />'; //if you wanted to know, for example, what groups they are a member of... echo '<pre>' . print_r($info[$i]['memberof'], true) . '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/51620-php-ldap-list-ous-and-sub-ous/#findComment-254382 Share on other sites More sharing options...
AndieB Posted June 7, 2007 Author Share Posted June 7, 2007 Thank you so much for your feedback! Follow-up question: Why do you use sAMAccoutname as filter? Does it work better that ObjectClass=*? Again, thank you very much for your time and effort! Sincerely, Andreas Once you query LDAP it returns basically a large multidimensional array that you can then parse through and use the data however you like...put in a new array or what-not... //connect to your ldap server $dn = "ou=sales, DC=USA"; //use your base DN here $filter = "(|(sAMAccountname=*))"; $search_result = ldap_search($ldap_connection, $db, $filter) or die(ldap_error($ldap_connection)); $result = ldap_get_entries($ldap_connection, $search_result); for ($i = 0; $i < $info['count']; $i++) { echo '<pre>' . print_r($info[$i], true) . '</pre><br />'; //if you wanted to know, for example, what groups they are a member of... echo '<pre>' . print_r($info[$i]['memberof'], true) . '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/51620-php-ldap-list-ous-and-sub-ous/#findComment-269825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.