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

Source for file add_entry.php

Documentation is available at add_entry.php

  1. <?php
  2. /**
  3. * This is a short example on how to add a new entry to your
  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. // We must define the DN of the new entry. The DN is the
  13. // global unique path to the data in the directory server,
  14. // similar to a path name in your filesystem.
  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. $dn 'cn=Foo Bar,'.$ldap_config['base'];
  19.  
  20.  
  21. // It is a good idea to first look if the entry, that should be added,
  22. // is already present:
  23. if ($ldap->dnExists($dn)) {
  24.     die('Could not add entry! Entry already exists!');
  25. }
  26.  
  27. // The entry does not exist so far, we can safely add him.
  28. // But first, we must construct the entry.
  29. // This is, because Net_LDAP was build to make changes only
  30. // locally (in your script), not directly on the server.
  31. $new_entry = new Net_LDAP_Entry(&$ldap$dn);
  32.  
  33. // We add some basic attributes:
  34. $new_entry->addarray(
  35.     'sn'             => 'Foo',
  36.     'gn'             => 'Bar',
  37.     'employeeNumber' => 123456
  38. ));
  39.  
  40. // Finally add the entry in the server:
  41. $result $ldap->add($new_entry);
  42. if (Net_LDAP::isError($result)) {
  43.     die('Unable to add entry: '.$result->getMessage());
  44. }
  45.  
  46. // The entry is now present in the directory server.
  47. ?>

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