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

Source for file modify_entry.php

Documentation is available at modify_entry.php

  1. <?php
  2. /**
  3. * This is a short example on how to modify a specific entry in the
  4. * directory using Net_LDAP.
  5. */
  6.  
  7. // We use the fetch_entry.php example to get the LDAP-Entry
  8. // which we will modify now.
  9. include_once 'fetch_entry.php';
  10.  
  11. // Okay, we should have a valid Net_LDAP_Entry object that represents
  12. // a real existing entry in our directory.
  13. // The changes are only locally made and executed on the server
  14. // at the end of the script.
  15.  
  16. // What we do now is to add two new attributes, one with two values
  17. // Note that we can add attribute values which we haven't selected
  18. // at fetching/searching the entry - but if we do that and
  19. // call getValues(), we will only see the values added and NOT all
  20. // attributes present on the server!
  21. $result $entry->add(array(
  22.     'mail'            => array('foo@example.org''test2@example.org'),
  23.     'telephoneNumber' => '1234567890'
  24. ));
  25. if (Net_LDAP::isError($result)) {
  26.     die('Unable to add attribute: '.$result->getMessage());
  27. }
  28.  
  29. // Now we modify the first value
  30. // Note, that we must give all old values, otherwise the attribute
  31. // will be deleted. We specify the new absolute attribute state
  32. $result $entry->replace(array('mail' => array('test1@example.org''test2@example.org')));
  33. if (Net_LDAP::isError($result)) {
  34.     die('Unable to modify attribute: '.$result->getMessage());
  35. }
  36.  
  37. // And now we delete the second attribute value
  38. // We must provide the old value, so the ldap server knows,
  39. // which value we want to be deleted
  40. $result $entry->delete(array('mail' => 'test2@example.org'));
  41. if (Net_LDAP::isError($result)) {
  42.     die('Unable to delete attribute value: '.$result->getMessage());
  43. }
  44.  
  45. // Finally, we delete the whole attribute 'telephoneNumber':
  46. $result $entry->delete('telephoneNumber');
  47. if (Net_LDAP::isError($result)) {
  48.     die('Unable to delete attribute: '.$result->getMessage());
  49. }
  50.  
  51. // Now it is time to transfer the changes to the ldap
  52. // directory. However, for security reasons, this line is
  53. // commented out.
  54.  
  55. /*
  56. $result = $entry->update();
  57. if (Net_LDAP::isError($result)) {
  58.     die('Unable to update entry: '.$result->getMessage());
  59. }
  60. */
  61. ?>

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