17.2 Removing an Entry from an LDAP Server


You want to delete an entry from an LDAP server.

Technique

Use the ldap_delete() function to delete object-level entries on your LDAP server:

 <?php // connect and bind, notice the password is specified // when we bind the connection $lh = ldap_connect("localhost") or die("Cannot connect to LDAP server"); ldap_bind($lh, "cn=root, o=Sterling's Company, c=US", "password")         or die("Cannot Bind"); // delete and close ldap_delete($lh, "cn=Doc Brown, o=Sterling's Company, c=US"); ldap_close($lh); ?> 

Comments

In this script, we delete the person Doc Brown from our directory. Doing so removes not only his entry but also all attributes associated with his entry. This is achieved by using the ldap_delete() function, which enables you to delete object-level entries from an LDAP server.

If you want to delete attributes from a specific dn , use the ldap_mod_del() function instead:

 <?php $lh = ldap_connect("localhost") or die("Cannot connect to LDAP server"); ldap_bind($lh, "cn=root, o=Sterling's Company, c=US", "password")          or die("Cannot Bind to LDAP server"); $delete_data = array("sn", "mail"); ldap_mod_del($lh, "cn=Doc Brown, o=Sterling's Company, c=US", $delete_data); ldap_close($lh); ?> 


PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net