PHP offers one
explicit function for accomplishing this, ldap_count_entries(). Its prototype follows:
int ldap_count_entries(resource link_id, resource result_id)
The following example returns the total number of LDAP records representing individuals
having a last name beginning with the letter G:
$results = ldap_search($connection, $dn, "sn=G*");
$count = ldap_count_entries($connection, $results);
echo "
Total entries retrieved: $count
";
This returns the following:
Total entries retrieved: 45
Sorting LDAP Records
The ldap_sort() function can sort a result set based on any of the returned result
attributes. Sorting is carried out by simply comparing the string values of each entry,
rearranging them in ascending order. Its prototype follows:
boolean ldap_sort(resource link_id, resource result, string sort_filter)
An example follows:
// Connect and bind...
$results = ldap_search($connection, $dn, "sn=G*", array("givenName", "sn"));
// Sort the records by the user's first name
ldap_sort($connection, $results, "givenName");
436 CHAPTER 17 ?– PHP AND LDAP
$entries = ldap_get_entries($connection,$results);
$count = $entries["count"];
for($i=0;$i<$count;$i++) {
printf("%s %s
",
$entries[$i]["givenName"][0], $entries[$i]["sn"][0]);
}
ldap_unbind($connection);
?>
This returns the following:
Jason Gilmore
John Gilmore
Robert Gilmore
Inserting LDAP Data
Inserting data into the directory is as easy as retrieving it.
Pages:
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515