This code sample shows how to move/rename an object in eDirectory in PHP using LDAP. The object can be moved within the same container or to different branch of the tree.
<?php
$server='localhost';
$admin='cn=admin,o=novell';
$passwd='novell';
$ds=ldap_connect($server); // assuming the LDAP server is on this host
if ($ds) {
$r=ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION, 3);
if(!$r) die("ldap_set_option failed");
// bind with appropriate dn to give update access
$r=ldap_bind($ds, $admin, $passwd);
if(!$r) die("ldap_bind failed<br>");
// prepare data
$r=ldap_rename($ds,"cn=pjones,ou=users,o=novell","cn=admin","ou=admins,o=novell",true);
if(!$r) die("ldap_rename failure<br>");
ldap_close($ds);
echo "ldap_rename success";
} else {
echo "Unable to connect to LDAP server";
}
?>
The third parameter is always required for eDirectory, even if the cn is not changing, the newrdn needs to be populated with the current cn, with cn= prepended to the actual cn. For example: ldap_rename($ds, "cn=test,ou=users,o=novell", "cn=test", "ou=newou,o=novell", true);
© 2008 Novell, Inc. All Rights Reserved.