Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3982

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Search LDAP tree</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ldap-sasl-bind.html">ldap_sasl_bind</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ldap-set-option.html">ldap_set_option</a></div>
 <div class="up"><a href="ref.ldap.html">LDAP Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.ldap-search" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_search</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">ldap_search</span> &mdash; <span class="dc-title">Search LDAP tree</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-search-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>ldap_search</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$base_dn</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$filter</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$attributes</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$attrsonly</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$sizelimit</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timelimit</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$deref</code></span>
  ]]]]] )</div>

  <p class="para rdfs-comment">
   Performs the search for a specified filter on the directory with the scope
   of <strong><code>LDAP_SCOPE_SUBTREE</code></strong>. This is equivalent to searching
   the entire directory.
  </p>
  <p class="para">
   From 4.0.5 on it&#039;s also possible to do parallel searches. To do this
   you use an array of link identifiers, rather than a single identifier,
   as the first argument. If you don&#039;t want the same base DN and the
   same filter for all the searches, you can also use an array of base DNs
   and/or an array of filters. Those arrays must be of the same size as
   the link identifier array since the first entries of the arrays are
   used for one search, the second entries are used for another, and so
   on. When doing parallel searches an array of search result
   identifiers is returned, except in case of error, then the entry
   corresponding to the search will be <strong><code>FALSE</code></strong>. This is very much like
   the value normally returned, except that a result identifier is always
   returned when a search was made. There are some rare cases where the
   normal search returns <strong><code>FALSE</code></strong> while the parallel search returns an
   identifier.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-search-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">link_identifier</code></em></span>
     <dd>

      <p class="para">
       An LDAP link identifier, returned by  <span class="function"><a href="function.ldap-connect.html" class="function">ldap_connect()</a></span>.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">base_dn</code></em></span>
     <dd>

      <p class="para">
       The base DN for the directory.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">filter</code></em></span>
     <dd>

      <p class="para">
       The search filter can be simple or advanced, using boolean operators in
       the format described in the LDAP documentation (see the <a href="http://www.mozilla.org/directory/csdk-docs/filter.htm" class="link external">&raquo;&nbsp;Netscape Directory SDK</a> for full
       information on filters).
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">attributes</code></em></span>
     <dd>

      <p class="para">
       An array of the required attributes, e.g. <em>array(&quot;mail&quot;, &quot;sn&quot;, &quot;cn&quot;)</em>.
       Note that the &quot;dn&quot; is always returned irrespective of which attributes
       types are requested.
      </p>
      <p class="para">
       Using this parameter is much more efficient than the default action
       (which is to return all attributes and their associated values). 
       The use of this parameter should therefore be considered good
       practice.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">attrsonly</code></em></span>
     <dd>

      <p class="para">
       Should be set to 1 if only attribute types are wanted. If set to 0
       both attributes types and attribute values are fetched which is the
       default behaviour.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">sizelimit</code></em></span>
     <dd>

      <p class="para">
       Enables you to limit the count of entries fetched. Setting this to 0
       means no limit.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        This parameter can NOT override server-side preset sizelimit. You can
        set it lower though.
       </p>
       <p class="para">
        Some directory server hosts will be configured to return no more than
        a preset number of entries. If this occurs, the server will indicate
        that it has only returned a partial results set. This also occurs if
        you use this parameter to limit the count of fetched entries.
       </p>
      </p></blockquote>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">timelimit</code></em></span>
     <dd>

      <p class="para">
       Sets the number of seconds how long is spend on the search. Setting
       this to 0 means no limit.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        This parameter can NOT override server-side preset timelimit. You can
        set it lower though.
       </p>
      </p></blockquote>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">deref</code></em></span>
     <dd>

      <p class="para">
       Specifies how aliases should be handled during the search. It can be
       one of the following:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_NEVER</code></strong> - (default) aliases are never
          dereferenced.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_SEARCHING</code></strong> - aliases should be
          dereferenced during the search but not when locating the base object
          of the search.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_FINDING</code></strong> - aliases should be
          dereferenced when locating the base object but not during the search.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_ALWAYS</code></strong> - aliases should be dereferenced
          always.
         </span>
        </li>
       </ul>
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-search-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a search result identifier or <strong><code>FALSE</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-search-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.0.5</td>
       <td>
        Parallel searches support was added.
       </td>
      </tr>

      <tr>
       <td>4.0.2</td>
       <td>
        The <em><code class="parameter">attrsonly</code></em>, <em><code class="parameter">sizelimit</code></em>,
        <em><code class="parameter">timelimit</code></em> and <em><code class="parameter">deref</code></em> were
        added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-search-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   The example below retrieves the organizational unit, surname,
   given name and email address for all people in &quot;My Company&quot; where
   the surname or given name contains the substring <var class="varname"><var class="varname">$person</var></var>. This
   example uses a boolean filter to tell the server to look for
   information in more than one attribute.
   <div class="example" id="example-4402">
    <p><strong>Example #1 LDAP search</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$ds&nbsp;is&nbsp;a&nbsp;valid&nbsp;link&nbsp;identifier&nbsp;for&nbsp;a&nbsp;directory&nbsp;server<br /><br />//&nbsp;$person&nbsp;is&nbsp;all&nbsp;or&nbsp;part&nbsp;of&nbsp;a&nbsp;person's&nbsp;name,&nbsp;eg&nbsp;"Jo"<br /><br /></span><span style="color: #0000BB">$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$filter</span><span style="color: #007700">=</span><span style="color: #DD0000">"(|(sn=</span><span style="color: #0000BB">$person</span><span style="color: #DD0000">*)(givenname=</span><span style="color: #0000BB">$person</span><span style="color: #DD0000">*))"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$justthese&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"ou"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"sn"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"givenname"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mail"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sr</span><span style="color: #007700">=</span><span style="color: #0000BB">ldap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filter</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$justthese</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_get_entries</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sr</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">"count"</span><span style="color: #007700">].</span><span style="color: #DD0000">"&nbsp;entries&nbsp;returned\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ldap-sasl-bind.html">ldap_sasl_bind</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ldap-set-option.html">ldap_set_option</a></div>
 <div class="up"><a href="ref.ldap.html">LDAP Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>