11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 17 • <strong>PHP</strong> AND LDAPwww.it-ebooks.infoRobert GilmoreInserting LDAP DataInserting data into the directory is as easy as retrieving it. In this section, two of <strong>PHP</strong>’s LDAP insertionfunctions are introduced.Adding a New EntryYou can add new entries to the LDAP directory with the ldap_add() function. Its prototype follows:Boolean ldap_add(resource link_id, string dn, array entry)An example follows, although keep in mind this won’t execute properly because you don’t possessadequate privileges to add users to the WJGilmore directory:Pretty simple, huh? But how would you add an attribute with multiple values? Logically, you woulduse an indexed array:$entry["displayName"] = "John Wayne";$entry["company"] = "Cowboys, Inc.";$entry["mail"][0] = "pilgrim@example.com";$entry["mail"][1] = "wayne.2@example.edu";ldap_add($connection, $dn, $entry) or die("Could not add new entry!");Adding to Existing EntriesThe ldap_mod_add() function is used to add additional values to existing entries, returning TRUE onsuccess and FALSE on failure. Its prototype follows:Boolean ldap_mod_add(resource link_id, string dn, array entry)Revisiting the previous example, suppose that the user John Wayne requested that another e-mailaddress be added. Because the mail attribute is multivalued, you can just extend the value array using<strong>PHP</strong>’s built-in array expansion capability. An example follows, although keep in mind this won’t execute360

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!