I'm doing a bunch of LDAP work with PHP-4.3.6 and keep running up against this annoyance. If I do an ldap_search() and get the first entry, I can't then tweak some of the attribute/values and then directly use ldap_add() to put a new version into the directory. The reason is that the ldap_get_entries() function returns any array or sub-array with a gratuitous "count" index.
For example, the following code (error checking removed for clarity): $results = ldap_search($ldapConn, $baseDN, "uid=cshenton"); $entries = ldap_get_entries($ldapConn, $results); $entry = $entries[0]; echo "entry=<pre>" . print_r($entry, true) . "</pre>"; Prints the following (with some tedious attribute/value pairs removed): entry= Array ( [cn] => Array ( [count] => 1 [0] => Chris Shenton-2 ) [0] => cn [sn] => Array ( [count] => 1 [0] => Shenton ) [1] => sn [objectclass] => Array ( [count] => 2 [0] => inetOrgPerson [1] => qmailUser ) ... [count] => 14 [dn] => cn=Chris Shenton-2,ou=Headquarters,o=National Aeronautics and Space Administration,c=us ) My code then fiddles with the old DN to create a new entry, then tries to add it to LDAP: if (! ldap_add($ldapConn, $newDN, $entry)) { die("ldap_add failed, errno=". ldap_errno($ldapConn) . ": " . ldap_error($ldapConn)); } It fails (but oddly, ldap_error() reports Success). The problem is the 'count' and attribute-named indices (e.g., 'sn') in addition to the numeric indices: Warning: ldap_add(): Value array must have consecutive indices 0, 1, ... in /home/cshenton/public_html/newhorseadmin/ldap_search_add_test.php on line 45 ldap_add failed, errno=0: Success Am I missing something or is it not possible to simply take a search result, then add it back? Seems I have to strip out all these gratuitous 'count' and non-numeric indices each time, which isn't intuitive, obvious, or the most direct way of doing things. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php