This code sample shows how to add objects or attributes to existing objects to eDirectory in PHP using LDAP.
<?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) die("ldap_bind failed<br>");
// prepare data
$entry["Surname"]="Jones";
$entry["objectclass"]="user";
$entry["mail"][0]="pjones@novell.com";
$entry["mail"][1]="othermail@novell.com";
// add data to directory
$r=ldap_add($ds, "cn=pjones,ou=users,o=novell", $entry);
if(!$r) die("ldap_add failure<br>");
ldap_close($ds);
echo "ldap_add success";
} else {
echo "Unable to connect to LDAP server";
}
?>
© 2009 Novell, Inc. All Rights Reserved.