Help with ldap_search for multiple DNs against AD

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benering
Forum Newbie
Posts: 2
Joined: Wed Jun 16, 2010 3:33 pm

Help with ldap_search for multiple DNs against AD

Post by benering »

Hello,
I am having an issue with getting results from multiple DNs in Active Directory via ldap_search. When I execute the below code, I get results back for one of the DNs or the other, never both. Can someone please help and tell me what my issue is? The interresting portion of the code is below:

Code: Select all

    
    $ad = ldap_connect("Server.Some.Domain", 389)
          or die("Couldn't connect to AD!");

    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

    $id[] = $ad;
    $id[] = $ad;

    $dn[] = "OU=US1-Users-UC,OU=FEUS1-UC,OU=FEUSX-UC,OU=UC,DC=Some,DC=Domain";
    $dn[] = "OU=US1-Users-UC,OU=US1-UC,OU=USX-UC,OU=Netbook-UC,OU=UC,DC=Some,DC=Domain";

    $attributes = array("displayname", "pwdlastset", "samaccountname", "mail", "givenname", "sn");

    $filter = "userAccountControl=512";

    $bd = ldap_bind($ad,"Some Account","Some Password")
          or die("Couldn't bind to AD!");

        $result = ldap_search($id, $dn, $filter, $attributes);

        $entries = false;

        foreach ($result as $value) {
            if(ldap_count_entries($ad, $value) > 0){
                $entries = $value;
                break;
            }
        }

        if($entries){
            $info = ldap_get_entries($ad, $entries);
        }else{
            $info = 'No results found';
        }
Any help would be appreciated!
benering
Forum Newbie
Posts: 2
Joined: Wed Jun 16, 2010 3:33 pm

Re: Help with ldap_search for multiple DNs against AD

Post by benering »

Bump.
Post Reply