Reputation: 1624
I need to make a Active directory search, for example I have the follow OU
OU=client,OU=office,OU=Administration,DC=domain,DC=local
How I can search a User (for example sAMAccountName='JUAN.PERZ') in the OU, using the memberof
instruction?
I use php to make the search with ldap_search.
I just need is to search a user, if the user is in the OU, using php,
Thanks!!!
Upvotes: 1
Views: 2020
Reputation: 72630
The thing you need is called ldap_search you can find a full sample here
<?php
// $ds is a valid connexion id (samAccountName)
$dn = "OU=client,OU=office,OU=Administration,DC=domain,DC=local";
$filter="(&(objectCategory=person)(samAccountName=$ds))";
$justtheseattributes = array( "ou", "sn", "givenname", "mail");
$sr=ldap_search($ds, $dn, $filter, $justtheseattributes);
$info = ldap_get_entries($ds, $sr);
echo $info["count"]." found entries.\n";
?>
Upvotes: 2
Reputation: 14648
All you need is ldap_search:
resource ldap_search ( resource $link_identifier , string $base_dn , string $filter [, array $attributes [, int $attrsonly [, int $sizelimit [, int $timelimit [, int $deref ]]]]] )
first parameter is resource from ldap_connect, second is your ou in form
"OU=client,OU=office,OU=Administration,DC=domain,DC=local"
third is filter in form
"sAMAccountName={$myADlogin}"
etc....
memberOf hold DN of group in LDAP, not an DN of OU!
Upvotes: 1