Pioden Posted September 10, 2009 Share Posted September 10, 2009 LDAP questions don't seem to get many responses here but undeterred I'm going to give it a go! I'm writing a little Ajax/PHP combo to search our college (LDAP) address book. I'm slowly getting to grips with the AJAX bits but the LDAP searching is giving me a serious headache! My code at the moment returns the entire LDAP record for the users it finds. Reams of stuff!! But all I really need is "departmentnumber" and "maillocaladdress" for matches to "uid". The equivalent SQL query would be simple: SELECT departmentnumber,maillocaladdress,uid FROM ldap WHERE uid = searchname (something like that anyway!) Can anybody point me in the right direction with filtering the LDAP search results? The stuff I've found on-line is confusing to say the least. TIA Huw <?php $username = "huw.*"; // LDAP variables $ldaphost = "ldapslave.mycollege.ac.uk"; // your ldap servers $ldapport = 389; // your ldap server's port number // Connecting to LDAP $ds = ldap_connect($ldaphost, $ldapport) or die ("Could not connect to $ldaphost"); //Connection made -- bind anonymously and get dn for username. $bind = @ldap_bind($ds); //Check to make sure we're bound. if( !bind ) { echo "Anonymous bind to LDAP FAILED."; exit; } // This is the stuff I can't get to work! // $filter="(|(uid=$username*))"; // $justthese = array("uid", "departmentnumber", "maillocaladdress"); $search = ldap_search($ds, "dc=mycollege,dc=ac,dc=uk", "uid=$username"/*$filter, $justthese*/); $info = ldap_get_entries($ds, $search); print_r ($search); ?> Link to comment https://forums.phpfreaks.com/topic/173757-searching-ldap/ Share on other sites More sharing options...
Pioden Posted September 10, 2009 Author Share Posted September 10, 2009 OK. I'm still hoping for replies - but I've also made a little progress! I've managed to filter out most of the info I don't need by modifying the query with some filtering $justthese = array("uid", "departmentnumber", "maillocaladdress"); $search = ldap_search($ds, "dc=mycollege,dc=ac,dc=uk", "uid=$username", $justthese); $info = ldap_get_entries($ds, $search); print_r ($info); This gives me all the data I need - but with a whole bunch of array info. Here's a snippet. Array ( [count] => 2 [0] => Array ( [uid] => Array ( [count] => 1 [0] => username1 ) [0] => uid [maillocaladdress] => Array ( [count] => 1 [0] => useremail ) [1] => maillocaladdress [departmentnumber] => Array ( [count] => 1 [0] => Engineering ) [2] => departmentnumber [count] => 3 [dn] => uid=username,ou=Users,dc=mycollege,dc=ac,dc=uk ) So the follow on question is how do I turn this into something useful? Is this a job for 'foreach' ? Sorry my brain is pretty fried at the moment!! Link to comment https://forums.phpfreaks.com/topic/173757-searching-ldap/#findComment-915982 Share on other sites More sharing options...
Pioden Posted September 10, 2009 Author Share Posted September 10, 2009 Shameless bump before I fall off the bottom of the page! No one able/willing to offer some insight? Link to comment https://forums.phpfreaks.com/topic/173757-searching-ldap/#findComment-916095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.