PHP Doku:: Liefert Merkmale eines Suchergebnis-Eintrags - function.ldap-get-attributes.html

Verlauf / Chronik / History: (50) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteLightweight Directory Access ProtocolLDAP Funktionenldap_get_attributes

Ein Service von Reinhard Neidl - Webprogrammierung.

LDAP Funktionen

<<ldap_free_result

ldap_get_dn>>

ldap_get_attributes

(PHP 4, PHP 5)

ldap_get_attributes Liefert Merkmale eines Suchergebnis-Eintrags

Beschreibung

array ldap_get_attributes ( resource $Verbindungs-Kennung , resource $Ergebnis-Eintrag-Kennung )

Rückgabewert: im Erfolgsfall wird die gesamte Information eines Eintrags in einem multidimensionalen Array zurückgegeben; im Fehlerfall FALSE.

Die ldap_get_attributes() Funktion wird verwendet um das Lesen der Merkmale und Werte eines Eintrags im Suchergebnis zu vereinfachen. Der Rückgabewert ist ein multidimensionales Array aus Merkmalen und Werten.

Nachdem Sie einen bestimmten Eintrag in dem Verzeichnis lokalisiert haben, können Sie mit dieser Funktion herausfinden, welche Informationen für diesen Eintrag verfügbar sind. Diese Funktion würden Sie in einer Anwendung verwenden, die Verzeichniseinträge "durchstöbert" und/oder wo Sie die Struktur der Verzeichniseinträge nicht kennen. In vielen Anwendungen suchen Sie nach einem bestimmten Merkmal wie einer email-Adresse oder einem Nachnamen und interessieren sich nicht dafür, welche anderen Daten verfügbar sind.

return_value["count"] = Anzahl der Merkmale des Eintrags
return_value[0] = das erste Merkmal
return_value[n] = das n-te Merkmal

return_value["merkmal"]["count"] = Anzahl der Werte des Merkmals
return_value["merkmal"][0] = der erste Wert des Merkmals
return_value["merkmal"][i] = der i+1-te Wert des Merkmals

Beispiel #1 Anzeigen der Liste der Merkmale für einen ausgewählten Verzeichnis-Eintrag

// $ds die Verbindungs-Kennung für das Verzeichnis

/* $sr ein gültiges Suchergebnis eines früheren Aufrufs einer der ldap
  Verzeichnis Suchfunktionen */

$entry = ldap_first_entry($ds, $sr);

$attrs = ldap_get_attributes($ds, $entry);

echo $attrs["count"]." Merkmale für diesen Eintrag:<p>";

for ($i=0; $i<$attrs["count"]; $i++)
    echo $attrs[$i]."<br>";

Siehe auch ldap_first_attribute() und ldap_next_attribute()


6 BenutzerBeiträge:
- Beiträge aktualisieren...
dunc at rumbletum dot org
18.10.2007 11:52
I spent quite a while scratching my head about how to read operational attributes such as create and modify timestamps.

This function solved it....

function get_entry_system_attrs( $ds, $dn, $deref=LDAP_DEREF_NEVER )
{
   $conn = $ds;
   $attrs = array( 'creatorsname', 'createtimestamp', 'modifiersname',
         'structuralObjectClass', 'entryUUID',  'modifytimestamp',
         'subschemaSubentry', 'hasSubordinates', '+' );
   $search = @ldap_read( $conn, $dn, '(objectClass=*)', $attrs, 0, 0, 0, $deref );
   if( ! $search )
      return false;
   $entry = ldap_first_entry( $conn, $search );
   if( ! $entry)
       return false;
   $attrs = ldap_get_attributes( $conn, $entry );
   if( ! $attrs )
      return false;
   if( ! isset( $attrs['count'] ) )
      return false;
   $count = $attrs['count'];
   unset( $attrs['count'] );
   $return_attrs = array();
   for( $i=0; $i<$count; $i++ ) {
      $attr_name = $attrs[$i];
      unset( $attrs[$attr_name]['count'] );
      $return_attrs[$attr_name] = $attrs[$attr_name];
   }
   return $return_attrs;
}
Snezko Snezak
27.07.2006 10: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
2.07.2004 19: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.07.2003 20: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
21.05.2002 5: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.06.2001 19: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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)