In the previous example the
$ds = ldap.myserver.com // your ldap server
should be
$ds = ldap_connect( "ldap.myserver.com" ) ; // your ldap server
ldap_read
(PHP 4, PHP 5)
ldap_read — Lee una entrada
Descripción
Devuelve un identificador de resultado de búsqueda o FALSE en caso de error.
ldap_read() realiza la búsqueda según el filtro especificado en el parámetro filtro con alcance LDAP_SCOPE_BASE, por lo que es equivalente a leer una entrada del directorio.
No se permiten filtros vacios. Si se quiere obtener toda la información de la entrada, se debe usar un filtro del tipo "objectClass=*". Si conoce que tipos de entradas son usadas en el servidor de directorio, es conveniente emplear el filtro apropiado, como por ejemplo "objectClass=inetOrgPerson".
La función admite hasta 5 parámetros opcionales. Consulte las notas de la función ldap_search().
Note: Los parámetros opcionales se añadieron en la versión de PHP 4.0.2: solo_atributos , tamano_limite , tiempo_limite , deref .
A partir de la versión de PHP 4.0.5 también es posible realizar búsquedas paralelas. Vea la función ldap_search() para ver más detalles.
ldap_read
30-Aug-2007 09:23
21-Dec-2005 08:21
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.
21-Aug-2003 11:11
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.
18-Jul-2001 11:15
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.
