Novell Home

Replace object attributes in eDirectory via LDAP in PHP

From Developer Community

This code sample shows how to modify an object by replacing attributes of the object in PHP via LDAP. The ldap_mod_replace function can also be used to add new attributes or delete existing attributes. You can delete attributes by passing an empty array as the new value, for example, $entry["mail"] = array(). You can change a users password here as well by setting the userPassword attribute to a new value.

Sample Code

<?php

$server='localhost';
$admin='cn=admin,o=novell';
$passwd='novell';

$ds=ldap_connect($server);  // assuming the LDAP server is on this host

if ($ds) {
    // bind with appropriate dn to give update access
    $r=ldap_bind($ds, $admin, $passwd);
	if($r) echo "ldap_bind success<br>";
    // prepare data
    $entry["mail"] ="anothermail@novell.com";

    // add data to directory
    $r=ldap_mod_replace($ds, "cn=pjones,ou=users,o=novell", $entry);
	if($r) echo "ldap_add success<br>";
	
    ldap_close($ds);
} else {
    echo "Unable to connect to LDAP server"; 
}
?>

--Paul Jones

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.