Net_LDAP
[ class tree: Net_LDAP ] [ index: Net_LDAP ] [ all elements ]

Source for file fetch_entry.php

Documentation is available at fetch_entry.php

  1. <?php
  2. /**
  3. * This is a short example on how to fetch a specific entry in the
  4. * directory using Net_LDAP.
  5. */
  6.  
  7. // We use the connecting.php example to get a link to our server.
  8. // This file will also include all required basic Net_LDAP classes.
  9. include_once 'connecting.php';
  10.  
  11. // Okay, we should have a valid link now.
  12. // Lets fetch an entry! We want to know the admins first and last name.
  13. // If we need additional attributes later, we must refetch the entry.
  14. // It is a good practice to only select the attributes really needed.
  15. // Since we want to be a little flexible, we make the base
  16. // dynamic, so it is enough to change the base-dn in your
  17. // $ldap_config array.
  18. $entry $ldap->getEntry('cn=admin,'.$ldap_config['base']array('gn''sn'));
  19.  
  20. // Error checking is important!
  21. if (Net_LDAP::isError($entry)) {
  22.     die('Could not fetch entry: '.$entry->getMessage());
  23. }
  24.  
  25. // Now fetch the data from the entry
  26. $surename  $entry->getValue('sn''single');
  27. if (Net_LDAP::isError($surename)) {
  28.     die('Unable to get surename: '.$surename->getMessage());
  29. }
  30. $givenname $entry->getValue('gn''single');
  31. if (Net_LDAP::isError($givenname)) {
  32.     die('Unable to get surename: '.$givenname->getMessage());
  33. }
  34.  
  35. // Finally output the data of the entry:
  36. // This will give something like "Name of cn=admin,o=example,dc=org: Foo Bar"
  37. echo 'Name of '.$entry->DN().': '.$givenname.' '.$surename;
  38. ?>

Documentation generated on Mon, 11 Mar 2019 15:32:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.