PHP: ldap_get_attributes - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ldap_get_dn ldap_free_result

Last updated: Sat, 27 Jan 2007

view this page in

# ldap_get_attributes

(PHP 3, PHP 4, PHP 5)

ldap_get_attributes -- Get attributes from a search result entry

## Description

array ldap_get_attributes ( resource link_identifier, resource result_entry_identifier )

Returns a complete entry information in a multi-dimensional array on success and `FALSE` on error.

ldap_get_attributes() function is used to simplify reading the attributes and values from an entry in the search result. The return value is a multi-dimensional array of attributes and values.

Having located a specific entry in the directory, you can find out what information is held for that entry by using this call. You would use this call for an application which "browses" directory entries and/or where you do not know the structure of the directory entries. In many applications you will be searching for a specific attribute such as an email address or a surname, and won't care what other data is held.

    return_value["count"] = number of attributes in the entry
    return_value[0] = first attribute
    return_value[n] = nth attribute

    return_value["attribute"]["count"] = number of values for attribute
    return_value["attribute"][0] = first value of the attribute
    return_value["attribute"][i] = (i+1)th value of the attribute

Пример 1. Show the list of attributes held for a particular directory entry

`<?php
// $ds is the link identifier for the directory
// $sr is a valid search result from a prior call to
// one of the ldap directory search calls
$entry = ldap_first_entry($ds, $sr);
$attrs = ldap_get_attributes($ds, $entry);
echo $attrs["count"] . " attributes held for this entry:<p>";
for ($i=0; $i<$attrs["count"]; $i++) {
echo $attrs[$i] . "<br />";
}
?>`

See also ldap_first_attribute() and ldap_next_attribute().

add a note User Contributed Notes
ldap_get_attributes
Snezko Snezak
27-Jul-2006 01:06
`Code and function to extract all attributes from all entryes in a certain DN. Maybe not the most timewise efficient but it works.
$entry = ldap_first_entry($ds, $sr);
write_attr($entry,$ds);
for ($i = 0; $i < $n_entries; $i++){
$entry = ldap_next_entry($ds, $entry);
write_attr($entry,$ds);
}
function write_attr($entry,$ds){
$attrs = ldap_get_attributes ($ds, $entry);
for ($j = 0; $j < $attrs["count"]; $j++){
$attr_name = $attrs[$j];
$attrs["$attr_name"]["count"] . "\n";
for ($k = 0; $k < $attrs["$attr_name"]["count"]; $k++) {
echo ">>>>>>";
echo $attr_name.": ".$attrs["$attr_name"][$k]."\n";
}
}
}`
php dot net at hiddemann dot org
02-Jul-2004 10:59
`Note that ldap_get_attributes fetches attributes AND values from the LDAP server. Depending on the data stored in the entry, the following code might work a dozen times faster (or even better, but faster in general) than the code in Example 1:
<?php
// $ds is the link identifier for the directory
// $sr is a valid search result from a prior call to
// one of the ldap directory search calls
$entry = ldap_first_entry($ds, $sr);
$attrs = array();
$attribute = ldap_first_attribute($ds,$entry,$identifier);
while ($attribute) {
$attrs[] = $attribute;
$attribute=ldap_next_attribute($ds,$entry,$identifier);
}
echo count($attrs) . " attributes held for this entry:<p>";
for ($i=0; $i<count($attrs); $i++) {
echo $attrs[$i] . "<br />";
}
?>
You may want to check the time difference with the function "microtime".`
kop at meme dot com
29-Jul-2003 11:28
`It's good practice to use array_change_key_case() on the result of ldap_get_attributes() so your program can ignore case in attribute names just like ldap itself does. (You wouldn't want ldap_get_attributes to _always_ flatten the case because you need a way to get the attribute names in a pretty format for display to the user.)`
allie at pajunas dot com
20-May-2002 08:52
`The array created by this function is similar to the on from ldap_get_entries() but when it creates array keys it alters the attribute's case inconsistently.
ldap_get_entries() lowercases all of the attributes before keying the array with them, but this function appears to leave things as they are.
If you're having problems, do a print_r and make sure you're using correct case for array keys. For example, you might need to use "objectClass" and not "objectclass".`
software at inebria dot com
21-Jun-2001 10:31
`As of PHP 4.0.5, the ldap_get_attributes function does not work with binary data. If you're fetching a JPEG from an LDAP server, use ldap_get_values_len instead.`
add a note
ldap_get_dn ldap_free_result

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST