Because the mail attribute is multivalued, you can
just extend the value array using PHP??™s built-in array expansion capability. An example
follows, although keep in mind this won??™t execute properly because you don??™t possess
adequate privileges to modify users residing in the OpenLDAP directory:
$dn = "ou=People,dc=OpenLDAP,dc=org";
$entry["mail"][] = "pilgrim@example.com";
ldap_mod_add($connection, $dn, $entry)
or die("Can't add entry attribute value!");
Note that the $dn has changed here because you need to make specific reference to
John Wayne??™s directory entry.
Suppose that John now wants to add his title to the directory. Because the title
attribute is single-valued it can be added like so:
$dn = "cn=John Wayne,ou=People,dc=OpenLDAP,dc=org";
$entry["title"] = "Ranch Hand";
ldap_mod_add($connection, $dn, $entry) or die("Can't add new value!");
438 CHAPTER 17 ?– PHP AND LDAP
Updating LDAP Data
Although LDAP data is intended to be largely static, changes are sometimes necessary.
PHP offers two functions for carrying out such modifications: ldap_modify(), for
making changes on the attribute level, and ldap_rename(), for making changes on the
object level. Both are introduced in this section.
Modifying Entries
The ldap_modify() function is used to modify existing directory entry attributes,
returning TRUE on success and FALSE on failure. Its prototype follows:
boolean ldap_modify(resource link_id, string dn, array entry)
With this function, you can modify one or several attributes simultaneously.
Pages:
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517