One of the easiest ways to do this is through the ldap_get_entries()
function, which offers an easy way to place all members of the result set into a multidimensional
array. Its prototype follows:
array ldap_get_entries(resource link_id, resource result_id)
The following list offers the numerous items of information that can be derived
from this array:
return_value["count"]: The total number of retrieved entries
return_value[n]["dn"]: The Distinguished Name (DN) of the nth entry in the
result set
return_value[n]["count"]: The total number of attributes available in the nth
entry of the result set
return_value[n]["attribute"]["count"]: The number of items associated with
the nth entry of attribute
return_value[n]["attribute"][m]: The mth value of the nth entry attribute
return_value[n][m]: The attribute located in the nth entry??™s mth position
Consider an example:
$host = "ldap.openldap.org";
$port = "389";
$dn = "dc=OpenLDAP,dc=Org";
$connection = ldap_connect($host)
or die("Can't establish LDAP connection");
CHAPTER 17 ?– PHP A ND LDAP 433
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($connection)
or die("Can't bind to the server.");
// Retrieve all records of individuals having first name
// beginning with letter K
$results = ldap_search($connection, $dn, "givenName=K*");
// Dump records into array
$entries = ldap_get_entries($connection, $results);
// Determine how many records were returned
$count = $entries["count"];
// Cycle through array and output name and e-mail address
for($x=0; $x < $count; $x++) {
printf("%s ", $entries[$x]["cn"][0]);
printf("(%s)
", $entries[$x]["mail"][0]);
}
?>
Executing this script produces output similar to this:
Kyle Billingsley (billingsley@example.
Pages:
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513