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.
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>