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

search for in the

ldap_rename> <ldap_parse_result
[edit] Last updated: Fri, 17 May 2013

view this page in

ldap_read

(PHP 4, PHP 5)

ldap_readLesen eines Eintrags

Beschreibung

resource ldap_read ( resource $Verbindungs-Kennung , string $basis_dn , string $filter [, array $merkmale [, int $nur_werte [, int $größenbegrenzung [, int $zeitbegrenzung [, int $deref ]]]]] )

Rückgabewert: Im Erfolgsfall eine Such-Ergebnis-Kennung, FALSE im Fehlerfall.

Die ldap_read() Funktion führt die Suche für einen gegebenen filter im Verzeichnis mit der Reichweite von LDAP_SCOPE_BASE durch. Das entpricht dem Lesen eines Eintrags in einem Verzeichnis.

Ein leerer Filter ist nicht erlaubt. Wenn Sie wirklich alle Informationen für einen Eintrag erhalten möchten, müssen Sie einen Filter der Art "objectClass=*" verwenden. Kennen Sie die Typen der Einträge die auf dem Verzeichnis-Server benutzt werden, können Sie einen passenden Filter wie z.B."objectClass=inetOrgPerson" verwenden.

Der Aufruf dieser Funktion nimmt 5 optionale Argumente entgegen. Siehe Anmerkungen zu ldap_search().

Hinweis:

Diese wahlfreien Argumente wurden in 4.0.2 hinzugefügt: nur_werte, größenbegrenzung, zeitbegrenzung, deref.

Seit der Version 4.0.5 ist es außerdem möglich parallele Suchen durchzuführen. Für Details siehe ldap_search().



ldap_rename> <ldap_parse_result
[edit] Last updated: Fri, 17 May 2013
 
add a note add a note User Contributed Notes ldap_read - [5 notes]
up
1
ronny at nxc dot no
2 months ago
The array in the attributes parameter needs to be an indexed array with numeric keys in ascending order. Like this:

Array
(
    [0] => this
    [1] => is
    [2] => a
    [3] => test
)

If there are missing keys in the array, then no result will be returned. This will not work:

Array
(
    [0] => this
    [1] => is
    [3] => test
)
up
1
cnicholl at yahoo dot com
7 years ago
Clarification of the ldap_read command syntax: 

If you just want to pull certain attributes from an object and you already know it's dn, the ldap_read command can do this as illustrated below.  It will be less overhead than ldap_search.

The string base_dn which is normally used to set the top context for a recursive ldap_search is used slightly differently with this command.  It is used to specify the actual object with the full dn.  (Hopefully this saves someone else a couple hours trying this command out.)

<?php
$ds
= ldap.myserver.com // your ldap server
 
$dn = "cn=username,o=My Company, c=US"; //the object itself instead of the top search level as in ldap_search
 
$filter="(objectclass=*)"; // this command requires some filter
 
$justthese = array("ou", "sn", "givenname", "mail"); //the attributes to pull, which is much more efficient than pulling all attributes if you don't do this
     
$sr=ldap_read($ds, $dn, $filter, $justthese);
         
$entry = ldap_get_entries($ds, $sr);

echo
$entry[0]["mail"][0] . "is the email address of the cn your requested";
echo
$entry[0]["sn"][0] . "is the sn of the cn your requested";
ldap_close($ds);
?>

This prints out the specified users mail and surname for example.
up
0
me at example dot com
5 years ago
In the previous example the

$ds = ldap.myserver.com // your ldap server

should be

$ds = ldap_connect( "ldap.myserver.com" ) ; // your ldap server
up
0
askegg at challenger dot com dot au
9 years ago
In addition to the above you can also use ldap_list for a ONE scope LDAP search.

PHP does not conform to the RFC's in that it does not use scope parameters.  Instead use ldap_read for a scope of BASE, ldap_list for ONE and ldap_search for SUB.
up
0
sbarnum at mac dot com
11 years ago
This differs from ldap_search() by not recursing down to sub-entries.  if you know the dn of the item you're looking for and only want info on that entry, use ldap_read() and pass it the full dn of the item you want.

It also seems that you'd alway want something like objectclass=* for the filter, since you're only searching on one entry.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites