I am using the ldap_get_values
function in a script that uses LDAP authentication.
My question is:
Is it possible to pull more than one value
(as the name suggests 'values') in one query
? Or does it have to be looped over (which to me doesnt really make sense as it would mean querying AD multiple times which would be inefficient?
My current function is this:
ldap_get_values($ds, $entry, "mail");
Which pulls the mail value.
I have found that I would need to use another property in the ldap_search function like this:
$attributes_ad = array(
"displayName",
"description",
"cn",
"givenName",
"sn",
"mail",
"co",
"mobile",
"company",
"displayName"
);
$sr = ldap_search(
$ds,
"cn=users,dc=servername,dc=com",
"(uid=$username)",
$attributes_ad
) or die ("Error in search query: ".ldap_error($ldapconn));
$entry = ldap_first_entry($ds,$sr);
$info = ldap_get_entries($ds, $sr);
//Now, to display the results we want:
for ($i=0; $i<$info["count"]; $i++)
{
// to show the attribute displayName (note the case!)
echo $info[$i]["mail"][0]."<br>";
echo $info[$i]["uid"][0]."<br>";
echo $info[$i]["displayname"][0]."<br>";
}