How can PHP be used to delete attributes and values in LDAP?

To delete attributes and values in LDAP using PHP, you can utilize the ldap_mod_del function. This function allows you to delete specific attributes or attribute values from an LDAP entry. You will need to establish a connection to the LDAP server, bind to it, and then use ldap_mod_del to delete the desired attributes or values.

<?php
$ldapserver = 'ldap.example.com';
$ldapuser = 'cn=admin,dc=example,dc=com';
$ldappass = 'password';

$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");

ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($ldapconn, $ldapuser, $ldappass) or die("Could not bind to LDAP server.");

$dn = "cn=John Doe,dc=example,dc=com";
$entry = array('attributeToDelete' => null);

if (ldap_mod_del($ldapconn, $dn, $entry)) {
    echo "Attribute successfully deleted.";
} else {
    echo "Error deleting attribute: " . ldap_error($ldapconn);
}

ldap_close($ldapconn);
?>