com)
Kurt Kramer (kramer@example.edu)
Kate Beckingham (beckingham.2@example.edu)
Retrieving a Specific Entry
You should use the ldap_read() function when you??™re searching for a specific entry
and can identify that entry by a particular DN. Its prototype follows:
resource ldap_read(resource link_id, string base_dn, string filter
[, array attributes [, int attributes_only [, int size_limit
[, int time_limit [int deref]]]]])
434 CHAPTER 17 ?– PHP AND LDAP
For example, to retrieve the first and last name of a user identified only by his user
ID, you might execute the following:
$host = "ldap.openldap.org";
// Who are we looking for?
$dn = "uid=wjgilmore,ou=People,dc=OpenLDAP,dc=Org";
// Connect to the LDAP server
$connection = ldap_connect($host)
or die("Can't establish LDAP connection");
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
// Bind to the LDAP server
ldap_bind($connection) or die("Can't bind to the server.");
// Retrieve the desired information
$results = ldap_read($connection, $dn, '(objectclass=person)',
array("givenName", "sn"));
// Retrieve an array of returned records
$entry = ldap_get_entries($connection, $results);
// Output the first and last names
printf("First name: %s
", $entry[0]["givenname"][0]);
printf("Last name: %s
", $entry[0]["sn"][0]);
// Close the connection
ldap_unbind($connection);
?>
This returns the following:
CHAPTER 17 ?– PHP A ND LDAP 435
First Name: William
Last Name: Gilmore
Counting Retrieved Entries
It??™s often useful to know how many entries are retrieved from a search.
Pages:
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514