Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : LDAP Functions : ldap_next_entry

ldap_next_entry

Get next result entry (PHP 4, PHP 5)
resource ldap_next_entry ( resource link_identifier, resource result_entry_identifier )


Code Examples / Notes » ldap_next_entry

m dot kooijman

The code listed below (posted by jeff) to print all attributes with their values is wrong. It keeps trying to index the $entry variable, which is a resource identifier, not an array. All the required information is in the return value of ldap_get_attributes, $attrs.
So:
$entry = ldap_next_entry($conn,$first_entry);
$attrs = ldap_get_attributes($conn,$entry);
for ($i=0; $i < $attrs["count"]; $i++) {
  $attr_name = $attrs[$i];
  for ($j=0; $j < $attrs[$attr_name]["count"]; $j++) {
    echo "$attr_name: ".$attrs["$attr_name"][$j]."\n";
  }
}


jeff

dahoo,
Your code to list the attributes of an entry isn't as complete as it could be--just listing the $result["attr"][0] value won't handle multiple-valued attributes. Instead, you should have something like:
$entry = ldap_next_entry($conn,$first_entry);
$attrs = ldap_get_attributes($conn,$entry);
for ($i=0; $i < $entry["count"]; $i++) {
  $attr_name = $entry[$i];
  for ($j=0; $j < $entry[$attr_name]["count"]; $j++) {
     echo "$attr_name: ".$entry["$attr_name"][$j]."\n";
  }
}
This enables you to get listings like:
dn: cn=admin,ou=Groups
cn: admin
objectClass: posixGroup
gidNumber: 500
memberUid: 604
memberUid: 605
(note the two values for "memberUid")
I hope this helps someone.
-Jeff


dahoo

An example :
for($i=ldap_first_entr($connect,$result);
   $arr=ldap_get_attributes($connect,$i);
   $i=ldap_next_entry($connect,$i))
{
foreach ($arr as $k => $v)
            {
$myrow[$k]=$arr[$k][0];
}
}


snameche

A short example :
$qry = ldap_search( $cxion, $ldap_base, '(cn=seb*)' );
$entry = ldap_first_entry( $cxion, $qry );
while( $entry ){
$dn = ldap_get_dn( $cxion, $entry );
echo "<b>$dn</b>
\n";
$attrs = ldap_get_attributes( $cxion, $entry );
for( $i=0; $i<$attrs['count']; $i++ ){
 echo "$attrs[$i]: ";
 for( $j=0; $j<$attrs[$attrs[$i]]['count']; $j++ )
  echo $attrs[$attrs[$i]][$j] . " ";
 echo "
\n";
}
echo "\
\n";
$entry = ldap_next_entry( $cxion, $entry );
}
ldap_free_result( $qry );


Change Language


Follow Navioo On Twitter
ldap_8859_to_t61
ldap_add
ldap_bind
ldap_close
ldap_compare
ldap_connect
ldap_count_entries
ldap_delete
ldap_dn2ufn
ldap_err2str
ldap_errno
ldap_error
ldap_explode_dn
ldap_first_attribute
ldap_first_entry
ldap_first_reference
ldap_free_result
ldap_get_attributes
ldap_get_dn
ldap_get_entries
ldap_get_option
ldap_get_values_len
ldap_get_values
ldap_list
ldap_mod_add
ldap_mod_del
ldap_mod_replace
ldap_modify
ldap_next_attribute
ldap_next_entry
ldap_next_reference
ldap_parse_reference
ldap_parse_result
ldap_read
ldap_rename
ldap_sasl_bind
ldap_search
ldap_set_option
ldap_set_rebind_proc
ldap_sort
ldap_start_tls
ldap_t61_to_8859
ldap_unbind
eXTReMe Tracker