ScotlandPHP

ldap_get_entries

(PHP 4, PHP 5, PHP 7)

ldap_get_entriesGet all result entries

Description

array ldap_get_entries ( resource $link_identifier , resource $result_identifier )

Reads multiple entries from the given result, and then reading the attributes and multiple values.

Parameters

link_identifier

An LDAP link identifier, returned by ldap_connect().

result_identifier

Return Values

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

The structure of the array is as follows. The attribute index is converted to lowercase. (Attributes are case-insensitive for directory servers, but not when used as array indices.)

return_value["count"] = number of entries in the result
return_value[0] : refers to the details of first entry

return_value[i]["dn"] =  DN of the ith entry in the result

return_value[i]["count"] = number of attributes in ith entry
return_value[i][j] = NAME of the jth attribute in the ith entry in the result

return_value[i]["attribute"]["count"] = number of values for
                                        attribute in ith entry
return_value[i]["attribute"][j] = jth value of attribute in ith entry

See Also

add a note add a note

User Contributed Notes 17 notes

up
6
tomas dot hampl at gmail dot com
5 years ago
It has been mentioned in the comments below, but the <?php ldap_get_entries($connection,$result) ?> always makes all attributes into lower-case. I found out the hard way that if I'm running an ldap query against the corporate AD and then want to display some results, nothing is actually displayed unless the attribute names area in lower-case.

Example:

<?php
// connect to AD
include('ad_con.php');
// limit attributes we want to look for
$attributes_ad = array("displayName","description","cn","givenName","sn","mail","co","mobile","company","displayName");
// define base
$base ="";

// in my script I search based on e-mail, $email variable is passed from the form
$result = ldap_search($conn, $base, "mail=$email*", $attributes_ad) or die ("Error in search
        query"
);

// put search results into the array ($conn variable is defined in the included 'ad_con.php')
$info = ldap_get_entries($conn, $result);

//Now, to display the results we want:
for ($i=0; $i<$info["count"]; $i++)
    {
   
// to show the attribute displayName (note the case!)
   
echo $info[$i]["displayname"][0]
   
    }

?>
up
1
Sebastien Troiani
7 years ago
Looks like there is a limit on returned objects - only 1000 items are placed in the array
s> , sos pmad> le="Vote cas // to shspaeach($ // to sh/ to sh# ( th)0 == n> ===ent">// to sh/ to shif($sh- === n>?&ult">?&unset($ <[$sh-]/Now, toult">?&ult">?&elseif(i/spe"echo ?&}ow, toult">?&d in tp$
2 <3180"
<3180" kstann / mack%at%inci5es
HPd in "> ref='/manual/en/refs.utilspec.w6-18 06:09class="tex14" id="Hcom95937">
&"> It has been mentioned in the comments below, f you'ruot;nual/en/feaA Dray indicng ineensitiass a hre'mmet/a> n', 'pwdmmetset'in ssre lar, you'lltribicehe corADbutesr /> -="doseconase.itss="defausfs.uo>.>.>6de>00:00:00s="default">&l Tocase-insdiv>s> itidnixftimef='mps whichual/en//en/ le="Votesidnderf='/d,an>e easyst thwould be$resulto loal/e: r />.>.>6de>-.>.>970t"ifte.othequery"conasow, toult">?&d in tp$dnix_timef='mpNow, to}v class="note" id="35541">
HPd in "> ref='/manual/en/refs.utilspeind3-11 08:2 class="tex8" id="Hcom95937">
&"> It has been mentioned in the comments below,R cursiveult <
$conn["Error iment">// to shspan class="keyword">);
"ErrorName"?&span pan class="keyword">[ldap_get_entries
$i<ldap_get_entr/ copan class="keyword">["count"]; // limian class="keyword">++)
    {
    // to sh/ to shifn class="keyword">=
$conn
, "count"span>"displayname"// to sh/ to sh/ to shspan class="keyword">);
""
["count"
span>"displayname"?&ult">?&ow the attribute displayName (note the
conaiVote should be$superflupagesosju somaly 100s cursivelcellow, toult">?&ult">?&ow the //al="sensitiyou ssrtucess and ameer"itii
  • an cperf.ow, toult">?&ult">?&ow the attribute displayNam>'ad_con.pfn ! empt/span>"count"]; // limia)cng i! isset(span class="keyword">);
    "count"
    span>"count"]; // limia/))mment">// to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    span>"count"]; // limia/ cpan class="keyword">[ $connspan>"count"
    ?&ult">?&ult">?&}ow, toult">?&ult">?&ult">?&elsemment">// to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    [ $connspan>"count"?&ult">?&ult">?&}ow, toult">?&ult">?&}ow, toult">?&ult">?&elsemment">// to sh/ to sh/ to sh/span>) or die (""["count"span>"displayname"?&ult">?&ow the pfn an class="keyword">["count"span>"displayname"]['>// limia == pan class="keyword">span>"Error iment">// to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    span>"displayname"["count"
    span>"displayname"?&ult">?&ult">?&}&elsemment">// to sh/ to sh/ to sh/ to shspan pan class="keyword">[ldap_get_entries
    $i<ldap_get_entr/ copan class="keyword">["count"span>"displayname"]['>// limian class="keyword"><    // to sh/ to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    span>"displayname"
    ["count"span>"displayname"?&ult">?&ult">?&ult">?&}ow, toult">?&ult">?&ult">?&}ow, toult">?&ult">?&}ow, toult">?&}ow, toult">?&d in tpspan class="keyword">);
    "count"
  • // to sh["uid=doe,ou=People,dc=return_,dc=net"]= // to sh/ to sh["uid"]= (4) "doe"ent">// to sh/ to sh["cn"]= (14) "John Doe"ent">// to sh/ to sh["telephone "]= (4) "1234"ow, toult">?&}ow, toult">?&["uid=foo,ou=People,dc=return_,dc=net"]= $conn["Error iment">// to sh/ to shspan class="keyword">);
    "ErrorName"
    ?&ult">?&span pan class="keyword">[ldap_get_entries$i<ldap_get_entr/ copan class="keyword">["count"]; // limian class="keyword">++)
        {
        // to sh/ to sh/ to sh/ to sh/span>) or die (""["count"
    span>"displayname"?&ult">?&ow the ow the pfn an class="keyword">["count"span>"displayname"]['>// limia == pan class="keyword">span>"Error iment">// to sh/ to sh/ to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    span>"displayname"["count"
    span>"displayname"?&ult">?&ult">?&ult">?&}&elsemment">// to sh/ to sh/ to sh/ to sh/ to sh/ to shspan pan class="keyword">[ldap_get_entries
    $i<ldap_get_entr/ copan class="keyword">[
    "count"span>"displayname"]['>// limian class="keyword"><    // to sh/ to sh/ to sh/ to sh/ to sh/ to sh/ to sh/ to shspan class="keyword">);
    "count"
    span>"displayname"
    ["count"span>"displayname"?&ult">?&ult">?&ult">?&ult">?&ult">?&}ow, toult">?&ult">?&ult">?&ult">?&}ow, toult">?&ult">?&}ow, toult">?&ult">?&d in tpspan class="keyword">);
    "count"
    2 61583"downno /manu35541" cla0s="name"> 61583"dkstann / mack%at%inci5es
    enanchor" href="#107267"> ¶
    HPd in "> ref='/manual/en/refs.utilspe2-02-09 06:43class="tex1t" id="Hcom107267">
    It has been mentioned in the comments below,A area i, />, becad> el="shortv>
    , e>
    up
    6 <48447downno /manu35541" cla0s="name"> <48447dkstann / mack%at%inci5es
    HPd in "> ref='/manual/en/refs.utilspe1-08-17 04:25class="tex16" id="Hcom107267">
    It has been mentioned in the comments below, and pons> iti/>r" d">r$fooretuwilltd in tp/>. ow, to ow, toInclass="ke /divtpis con$fooretuwilltd in tp/> 'dn>ute&Pd ticular, raa hrs/> dn) raa hrs/>vtpitpis cotiple vals are al/enorkst"ifte.ott inte&eia hrsclass ow, to ow, toFn seebuggal/eies
    HPd in "> ref='/manual/en/refs.utilspe1-05-1t"09:51">ass="tex16" id="Hcom107267">
    &"> It has been mentioned in the comments below,Nss=:eel="shortcut iconfunctisbtr ees aifhno eyword">truoltug ,
    6 no /manu35541" cla0s="name">
    ref='/manual/en/refs.utilspe0-12-20 ass="tex16" id="Hcom107267">
    It has been mentioned in the comments below,Ju soa ass=:ee ctrongdeme>FALSEi a hrevtpis conn/feaitpitpis co355.tyoue elelt;? tThePd cutpis co[],umyAded [2] ow, to ow, toSo,hs cos whinyou
    HPd in "> ref='/manual/en/refs.utilspe4-e4-21 03:57class="tex13" id="Hcom95937">
    &"> It has been mentioned in the comments below, f you$attp lvhrs/>// to sh/ to shifn ais_null(p$cut ico[ $i ] )m)sesetteueNow, toult">?&ult">?&...vw, to}v class="note" id="35541">
    HPd in "> ref='/manual/en/refs.utilspe7.win21 02:48class="tex10" id="Hcom95937">
    &"> It has been mentioned in the comments below,Snlesesde Iriabltoassher. Mayb> yellsce cbenefit'lt">$it.lt">&lspan>// connect to AD
    is d_eyword"> $connspan>$i// to shspaeachn class="keyword">=ldap_get_entras class="keyword">++)
     nfn>"Error iment">// to sh/ to shifn class="keyword">=$conn
    , "Error smment">// to sh/ to sh/ to shspaeachn class="keyword">=ldap_get_entras class="keyword">++)
     sh- class="default">ldap_get_entri=
    "Error iment">// to sh/ to sh/ to sh/ to shifn class="keyword">=$conn, "Errorspan>   {
        r)>- pan class="keyword">span>"Error i=$i// to sh/ to sh/ to sh/ to sh/ to shifn class="keyword">=
    $conn
    , "Error smment">// to sh/ to sh/ to sh/ to sh/ to sh/ to shunset(an class="keyword">, "Errorspan>   {
        rspan class="keyword">];
    $i?&ult">?&/ to sh/ to shult">?&}ow, toult">?&ult">?&ult">?&ult">?&/ to shspan class="keyword">);
    $conn
      {
        r cpan class="keyword">[
    "Errorspan>   {
        rNow, toult">?&ult">?&ult">?&ult">?&}ow, toult">?&ult">?&ult">?&}ow, toult">?&ult">?&}ow, toult">?&}ow, toult">?&span class="keyword">);
    $conn
    ]["mail"[
    $conn
    ,word">][',>// limi>);
    $i
    ][    }]["mail"?&d in tpspan class="keyword">);
    $conn
    $d> class="default">ldap_get_entries][// in my script I search based on e $ds class="keyword">++)<_get_entriesinclass="default">$conn,word">]["el="://DOMAIN.net"n>"Error ;ow, toifn class="keyword">= $conn// to shspan class="keyword">);
    ++)<_get_entries
    "Error class="keyword">= $conn// to shspan class="keyword">);
    ++)<_get_entries
    $conn, $conn$email $conn$email $conn
    $d> > $conn// to shspan class="keyword">);
    ldap_get_entries($conn, $conn$>);
    $conn// to shsnt">// to shn>[$i][$i ]; //.span> $d> > $conn ]; // in my / to shsnt">// to shspan class="keyword">);
    ldap_get_entries
    $connspan>$i?&spaeachn class="keyword">=ldap_get_entras class="keyword">++)
     sh- class="default">ldap_get_entri=
    //mment">// to sh/ to shn>[]; //.span> $g">   {
        .span> ]; // in my / to sh/ to shifn class="keyword">=$conn
    ,
    //)ment">// to sh/ to sh/ to shspaeachpan class="keyword">, < class="default">ldap_get_entras class="keyword">++)
     r class="default">$conn// to sh/ to sh/ to sh/ to shn>[]; //.span> $r class="default">$conn ]; // in my / to sh/ to shult">?&}ow, toult">?&ult">?&}ow, toult">?&}ow, toult">?&span class="keyword">);
    el="srlosilass="default">$conn
    ,pan> $conn/}vn>
    up
    2 514 cefs.utilsp 514 ce>
    ref='/manual/en/refs.utilspe0-04-17 10:03class="tex1t" id="Hcom95937">
    It has been mentioned in the comments below,Nss=es corel="shortcut iconfuncti aasspaocia/li> uded 'n/feaiv> i>
    ?&Soibut return_niv> utesnNan> <)ef="#ctems art.utsesefu hd thtbf= D.l class="note" id="35541">
    up
    2 901267down 901267d>
    enanchor" href="#107267"> ¶
    HPd in "> ref='/manual/en/refs.utilspeind4-07 09:09class="tex8" id="Hcom95937">
    It has been mentioned in the comments below,Hopref="#ccould lelpms bit oshersucasprd"t v> san>&l/code>
    / connect to ADpan>++)<_get_entriesinclass="default">$conn,pan>$conn,word">]["Could n href">inc$ro sprv . Errn s c" class="keyword">++)<_get_entr.es$conn,pan>//);script I search based on e
    $el="sbd class="keyword">++)<_get_entries"Error class="keyword">=/span class="default">$>);
    /span class="default">$>);
    $conn
    ,word">]["Could n hrbina$ro sprv . Errn s c" class="keyword">++)<_get_entr.s
    $conn,pan>//);script I search based on e
    $br />< class="default">ldap_get_entries$conn, /span class="default">$>);
    il_basilass="default">$conn
    $email"Error in sdien class="keyword">="Error ;ow, toscript I search based on e $d nu class="default">ldap_get_entries($conn, /span class="default">$>);
    //;ow, toscriptlor (pan class="keyword">span>ldap_get_entripan class="keyword">span>    }++)
        {
        / coipan class="keyword">span>$i
    ][$i++)
        {
        // to sh/ to sh/ to sh/ to shlor (pan class="keyword">span>    ipan class="keyword">span>    }span>    / coipan class="keyword">span>$i
    ]["displayname"][$i++)
     j   {
        // to sh/ to sh/ to sh/ to shn>[span>$i]["displayname"][  pj   {
        r.span>
    ]; //.span>
    $d nulass="default">$i]["displayname"][  pd nulass="default">$i]["displayname"][  pj   {
        r/span>// in my / to sh/ to shult">?&ult">?&}ow, to}vn> el="srlosilass="default">$conn
    ,pan>//;script I search based on e
    page=function.ldaaddt-entries&since="Vote up!" class="usernotes-vrediay i=htt"://fr2ries.nettion.ldaen/="Vote up!" class="usernories">pimg src='/images/ass="tadd@2x.png' alt='addoa ass=' width='12' leight='12'> addoa ass="ncmall> "> r> ="nameceote u>