<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.ldap.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.ldap-search.php',
    1 => 'ldap_search',
    2 => 'Search LDAP tree',
  ),
  'up' => 
  array (
    0 => 'ref.ldap.php',
    1 => 'Функції LDAP',
  ),
  'prev' => 
  array (
    0 => 'function.ldap-sasl-bind.php',
    1 => 'ldap_sasl_bind',
  ),
  'next' => 
  array (
    0 => 'function.ldap-set-option.php',
    1 => 'ldap_set_option',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ldap/functions/ldap-search.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.ldap-search" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_search</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</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">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_search</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.ldap-connection.php" class="type LDAP\Connection">LDAP\Connection</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$ldap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$base</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$filter</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$attributes</code><span class="initializer"> = []</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$attributes_only</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$sizelimit</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$timelimit</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$deref</code><span class="initializer"> = <strong><code><a href="ldap.constants.php#constant.ldap-deref-never">LDAP_DEREF_NEVER</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$controls</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="class.ldap-result.php" class="type LDAP\Result">LDAP\Result</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></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">Також можливо шукати паралельно.
Тоді перший параметр має бути масивом примірників
<span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span>. Якщо пошуковики мають використовувати
різні базові DN і фільтр, то небхідно передати масив базових DN і/або
масив фільтрів, як параметри. Ці масиви мають бути однакових розмірів з масивом
примірників <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span>, оскільки перші елементи
масивів використовуються для одного пошуку, другі використовуються для іншого і
так далі. Виконавши паралельний пошук, повернеться масив примірників
<span class="classname"><a href="class.ldap-result.php" class="classname">LDAP\Result</a></span>, окрім випадків помилок, коли значення, що
повернеться, буде <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.</p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-search-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">ldap</code></dt>
     <dd>
      <p class="para">
       Примірник <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span>, якого
повертає <span class="function"><a href="function.ldap-connect.php" class="function">ldap_connect()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">base</code></dt>
     <dd>
      <p class="para">
       The base DN for the directory.
      </p>
     </dd>
    
    
     <dt><code class="parameter">filter</code></dt>
     <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="https://wiki.mozilla.org/Mozilla_LDAP_SDK_Programmer%27s_Guide/Searching_the_Directory_With_LDAP_C_SDK" class="link external">&raquo;&nbsp;Netscape Directory SDK</a> or
       <a href="https://datatracker.ietf.org/doc/html/rfc4515" class="link external">&raquo;&nbsp;RFC4515</a> for full
       information on filters).
      </p>
     </dd>
    
    
     <dt><code class="parameter">attributes</code></dt>
     <dd>
      <p class="para">
       An array of the required attributes, e.g. <code class="literal">array(&quot;mail&quot;, &quot;sn&quot;, &quot;cn&quot;)</code>.
       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><code class="parameter">attributes_only</code></dt>
     <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><code class="parameter">sizelimit</code></dt>
     <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">Зауваження</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><code class="parameter">timelimit</code></dt>
     <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">Зауваження</strong>: 
       <p class="para">
        This parameter can NOT override server-side preset timelimit. You can
        set it lower though.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">deref</code></dt>
     <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><a href="ldap.constants.php#constant.ldap-deref-never">LDAP_DEREF_NEVER</a></code></strong> - (default) aliases are never
          dereferenced.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code><a href="ldap.constants.php#constant.ldap-deref-searching">LDAP_DEREF_SEARCHING</a></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><a href="ldap.constants.php#constant.ldap-deref-finding">LDAP_DEREF_FINDING</a></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><a href="ldap.constants.php#constant.ldap-deref-always">LDAP_DEREF_ALWAYS</a></code></strong> - aliases should be dereferenced
          always.
         </span>
        </li>
       </ul>
      </p>
     </dd>
    
    
     <dt><code class="parameter">controls</code></dt>
     <dd>
      <p class="para">
       Array of <a href="ldap.controls.php" class="link">LDAP Controls</a> to send with the request.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-search-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Повертає примірника <span class="classname"><a href="class.ldap-result.php" class="classname">LDAP\Result</a></span>, масив примірників
<span class="classname"><a href="class.ldap-result.php" class="classname">LDAP\Result</a></span>, або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-search-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
 <td>8.1.0</td>
 <td>
  Тепер параметр <code class="parameter">ldap</code> має бути примірником
  <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span>; раніше очікувався дійсний <a href="language.types.resource.php" class="link">resource</a>
  <code class="literal">ldap link</code>.
 </td>
</tr>

      <tr>
 <td>8.1.0</td>
 <td>
  Тепер повертає примірника <span class="classname"><a href="class.ldap-result.php" class="classname">LDAP\Result</a></span>; раніше
  повертався <a href="language.types.resource.php" class="link">resource</a>.
 </td>
</tr>

      <tr>
 <td>8.0.0</td>
 <td>
  Параметр <code class="parameter">controls</code> тепер може бути <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>; раніше
  початково було <code class="literal">[]</code>.
 </td>
</tr>

      <tr>
       <td>7.3.0</td>
       <td>
        Support for <code class="parameter">controls</code> added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-search-examples">
  <h3 class="title">Приклади</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">$person</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-1">
    <p><strong>Приклад #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">// $ds is a valid LDAP\Connection instance for a directory server<br /><br />// $person is all or part of a person's name, eg "Jo"<br /><br /></span><span style="color: #0000BB">$dn </span><span style="color: #007700">= </span><span style="color: #DD0000">"o=My Company, 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 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"ou"</span><span style="color: #007700">, </span><span style="color: #DD0000">"sn"</span><span style="color: #007700">, </span><span style="color: #DD0000">"givenname"</span><span style="color: #007700">, </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">, </span><span style="color: #0000BB">$dn</span><span style="color: #007700">, </span><span style="color: #0000BB">$filter</span><span style="color: #007700">, </span><span style="color: #0000BB">$justthese</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$info </span><span style="color: #007700">= </span><span style="color: #0000BB">ldap_get_entries</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">, </span><span style="color: #0000BB">$sr</span><span style="color: #007700">);<br /><br />echo </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">" entries returned\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


</div><?php manual_footer($setup); ?>