Page 1 of 1

Help with ldap_search for multiple DNs against AD

Posted: Wed Jun 16, 2010 3:42 pm
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!

Re: Help with ldap_search for multiple DNs against AD

Posted: Mon Aug 23, 2010 1:50 pm
by benering
Bump.