Reputation: 65
I'm trying to retreive the information of user using the user's id from Ldap internal server.
I've already a script to get the informations from my OU but i'd like to get the informations of an user from any OU. (it can be from any OU of my enterprise.
I hope you could help me :)
$ldap = ldap_connect("LDAP://xxxxxxxx/", 389)
or die;
$ldapuser = 'user';
$ldappass = 'pass';
$BaseDN = "OU=Utilisateurs,OU=AF,OU=M_Viy,OU=Ressources_Locales,DC=COMMUN,DC=AD,DC=xxxx,DC=FR";
// $RootDN = 'CN=LDAP User,OU=Comptes_Generiques_Attente,OU=M_Vitry,OU=Ressources_Locales,DC=COMMUN,DC=AD,DC=xxxxx,DC=FR';
// $ConnectionFilter = '(&(objectClass=user)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))';
if ($bind = ldap_bind($ldap, $ldapuser, $ldappass))
{
$attributes_ad = array("displayName","givenname","sn","samaccountname","telephonenumber","mail","extensionattribute7","mobile","company","displayName");
$cpuser = $infos['user'];
$result = ldap_search($ldap, $BaseDN, "samaccountname=$cpuser", $attributes_ad);
$info = ldap_get_entries($ldap, $result);
print_r($info);
}
Upvotes: 0
Views: 6306
Reputation: 116
Might I suggest changing your Base DN from
$BaseDN = "OU=Utilisateurs,OU=AF,OU=M_Viy,OU=Ressources_Locales,DC=COMMUN,DC=AD,DC=xxxx,DC=FR";
to just
$BaseDN = "DC=COMMUN,DC=AD,DC=xxxx,DC=FR";
and setting the appropriate filter. So instead of "samaccountname=$cpuser"
, try using
"(&(objectCategory=person)(sAMAccountName=*))"
.
This should allow you to get any user from any OU within your domain.
Upvotes: 1