Home arrow PHP arrow Page 6 - Using PHP With LDAP (part 2)

Wiping Out The Past - PHP

In this second, and concluding, article, dig deeper into PHP'sLDAP API by writing complex search queries and building a Web-basedadministration module to retrieve and modify entries from the LDAP directorytree.

TABLE OF CONTENTS:
  1. Using PHP With LDAP (part 2)
  2. Of Needles And Haystacks
  3. Making Lists
  4. Adding It All Up
  5. Changing Things Around
  6. Wiping Out The Past
  7. To Err Is Human...
  8. Endgame
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 9
April 07, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
So that takes care of listing, adding and modifying entries. All that's left is to delete entries.

Again, this is similar to modifying entries - "delete.php", the script to invoke entry deletion is accessed from the main index page, and is passed the user's email address using the URL GET method. This email address is then used by the PHP script to identify the corresponding entry and remove it via the ldap_delete() command.






<html> <head> </head> <body> <?php // specify the LDAP server to connect to $conn = ldap_connect("localhost") or die("Could not connect to server. Error is " . ldap_error($conn)); // set privileged user $root_dn = "cn=root, dc=my-domain, dc=com"; $root_pw = "secret"; // bind to the LDAP server specified above $r = ldap_bind($conn, $root_dn, $root_pw) or die("Could not bind to server. Error is " . ldap_error($conn)); // prepare DN for entry to delete $dn = "mail=".$_GET['mail'].", dc=my-domain, dc=com"; // delete the entry from the directory $result=ldap_delete($conn, $dn) ; // if successful, display success message if($result) { echo "Entry with DN " . $dn . " deleted from LDAP directory."; } // else display error else { echo "An error occurred. Error number " . ldap_errno($conn) . ": " . ldap_err2str(ldap_errno($conn)); } // all done? clean up ldap_close($conn); ?> </body> </html>
Here's the output:



 
 
>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap

Dev Shed Tutorial Topics: