<?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-compare.php',
    1 => 'ldap_compare',
    2 => 'Compare value of attribute found in entry specified with DN',
  ),
  'up' => 
  array (
    0 => 'ref.ldap.php',
    1 => 'Функції LDAP',
  ),
  'prev' => 
  array (
    0 => 'function.ldap-close.php',
    1 => 'ldap_close',
  ),
  'next' => 
  array (
    0 => 'function.ldap-connect.php',
    1 => 'ldap_connect',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ldap/functions/ldap-compare.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.ldap-compare" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_compare</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ldap_compare</span> &mdash; <span class="dc-title">Compare value of attribute found in entry specified with DN</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-compare-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_compare</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.ldap-connection.php" class="type LDAP\Connection">LDAP\Connection</a></span> <code class="parameter">$ldap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$dn</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$attribute</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$value</code></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="language.types.boolean.php" class="type bool">bool</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span></div>

  <p class="para rdfs-comment">
   Compare <code class="parameter">value</code> of <code class="parameter">attribute</code>
   with value of same attribute in an LDAP directory entry.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-compare-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">dn</code></dt>
     <dd>
      <p class="para">
       The distinguished name of an LDAP entity.
      </p>
     </dd>
    
    
     <dt><code class="parameter">attribute</code></dt>
     <dd>
      <p class="para">
       The attribute name.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       The compared value.
      </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-compare-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if <code class="parameter">value</code> matches otherwise returns
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Returns -1 on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-compare-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.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-compare-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   The following example demonstrates how to check whether or not given password matches
   the one defined in DN specified entry.
  </p>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Complete example of password check</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$ds</span><span style="color: #007700">=</span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">);  </span><span style="color: #FF8000">// assuming the LDAP server is on this host<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$ds</span><span style="color: #007700">) {<br /><br />    </span><span style="color: #FF8000">// bind<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">ldap_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">)) {<br /><br />        </span><span style="color: #FF8000">// prepare data<br />        </span><span style="color: #0000BB">$dn </span><span style="color: #007700">= </span><span style="color: #DD0000">"cn=Matti Meikku, ou=My Unit, o=My Company, c=FI"</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$value </span><span style="color: #007700">= </span><span style="color: #DD0000">"secretpassword"</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$attr </span><span style="color: #007700">= </span><span style="color: #DD0000">"password"</span><span style="color: #007700">;<br /><br />        </span><span style="color: #FF8000">// compare value<br />        </span><span style="color: #0000BB">$r</span><span style="color: #007700">=</span><span style="color: #0000BB">ldap_compare</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">$attr</span><span style="color: #007700">, </span><span style="color: #0000BB">$value</span><span style="color: #007700">);<br /><br />        if (</span><span style="color: #0000BB">$r </span><span style="color: #007700">=== -</span><span style="color: #0000BB">1</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"Error: " </span><span style="color: #007700">. </span><span style="color: #0000BB">ldap_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">);<br />        } elseif (</span><span style="color: #0000BB">$r </span><span style="color: #007700">=== </span><span style="color: #0000BB">true</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"Password correct."</span><span style="color: #007700">;<br />        } elseif (</span><span style="color: #0000BB">$r </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"Wrong guess! Password incorrect."</span><span style="color: #007700">;<br />        }<br /><br />    } else {<br />        echo </span><span style="color: #DD0000">"Unable to bind to LDAP server."</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #0000BB">ldap_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">);<br /><br />} else {<br />    echo </span><span style="color: #DD0000">"Unable to connect to LDAP server."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.ldap-compare-notes">
  <h3 class="title">Примітки</h3>
  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    <span class="function"><strong>ldap_compare()</strong></span> can NOT be used to compare BINARY values!
   </p>
  </div>
 </div>


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