<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); include_once dirname(__FILE__) ."/toc/book.ldap.inc"; $setup = array ( 'home' => array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'ldap.controls.php', 1 => 'LDAP controls', ), 'up' => array ( 0 => 'book.ldap.php', 1 => 'LDAP', ), 'prev' => array ( 0 => 'ldap.using.php', 1 => 'Using the PHP LDAP calls', ), 'next' => array ( 0 => 'ldap.examples.php', 1 => 'Examples', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ldap/controls.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <div id="ldap.controls" class="chapter"> <h1 class="title">LDAP controls</h1> <p class="para"> Controls are special objects which may be sent alongside an LDAP request to alter LDAP server behavior while performing the request. There may also be controls sent by the server alongside the response to provide more information, usually to answer a control object from the request. <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Not all controls are supported by all LDAP servers. To know which controls are supported by a server, you need to query the root DSE by reading an empty dn with the filter (objectClass=*). </p> <div class="example" id="example-4611"> <p><strong>Example #1 Testing support for paged result control</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// $ds is a valid link identifier for a directory server<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">ldap_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #DD0000">'(objectClass=*)'</span><span style="color: #007700">, [</span><span style="color: #DD0000">'supportedControl'</span><span style="color: #007700">]);<br />if (!</span><span style="color: #0000BB">in_array</span><span style="color: #007700">(</span><span style="color: #0000BB">LDAP_CONTROL_PAGEDRESULTS</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">$result</span><span style="color: #007700">)[</span><span style="color: #0000BB">0</span><span style="color: #007700">][</span><span style="color: #DD0000">'supportedcontrol'</span><span style="color: #007700">])) {<br /> die(</span><span style="color: #DD0000">"This server does not support paged result control"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p></blockquote> </p> <p class="para"> As of PHP 7.3, you can send controls with your request in all request functions using the <code class="parameter">controls</code> parameter. When a ext version of a function exists, you should use it if you want to get access to the full response object and be able to parse response controls from it using <span class="function"><a href="function.ldap-parse-result.php" class="function">ldap_parse_result()</a></span>. </p> <p class="para"> <code class="parameter">controls</code> must be an array containing an array for each control to send, containing the following keys: <dl> <dt> oid (<span class="type"><a href="language.types.string.php" class="type string">string</a></span>) </dt> <dd> <span class="simpara"> The OID of the control. You should use constants starting with LDAP_CONTROL_ for this. See <a href="ldap.constants.php" class="link">LDAP Constants</a>. </span> </dd> <dt> iscritical (<span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>) </dt> <dd> <span class="simpara"> If a control is noted as critical, the request will fail if the control is not supported by the server, or if it fails to be applied. Note that some controls should always be marked as critical as noted in the RFC introducing them. Defaults to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. </span> </dd> <dt> value (<span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span>) </dt> <dd> <span class="simpara"> If applicable, the value of the control. Read below for more information. </span> </dd> </dl> </p> <p class="para"> Most control values are sent to the server BER-encoded. You may either BER-encode the value yourself, or you can instead pass an array with the correct keys so that the encoding is done for you. Supported controls to be passed as an array are: <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-pagedresults">LDAP_CONTROL_PAGEDRESULTS</a></code></strong> Expected keys are [size] and [cookie] </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-assert">LDAP_CONTROL_ASSERT</a></code></strong> Expected key is filter </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-valuesreturnfilter">LDAP_CONTROL_VALUESRETURNFILTER</a></code></strong> Expected key is filter </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-pre-read">LDAP_CONTROL_PRE_READ</a></code></strong> Expected key is attrs </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-post-read">LDAP_CONTROL_POST_READ</a></code></strong> Expected key is attrs </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-sortrequest">LDAP_CONTROL_SORTREQUEST</a></code></strong> Expects an array of arrays with keys attr, [oid], [reverse]. </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-vlvrequest">LDAP_CONTROL_VLVREQUEST</a></code></strong> Expected keys are before, after, attrvalue|(offset, count), [context] </p> </li> </ul> </p> <p class="para"> The following controls do not need any value: <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-passwordpolicyrequest">LDAP_CONTROL_PASSWORDPOLICYREQUEST</a></code></strong> </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-managedsait">LDAP_CONTROL_MANAGEDSAIT</a></code></strong> </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-dontusecopy">LDAP_CONTROL_DONTUSECOPY</a></code></strong> </p> </li> </ul> </p> <p class="para"> The control <strong><code><a href="ldap.constants.php#constant.ldap-control-proxy-authz">LDAP_CONTROL_PROXY_AUTHZ</a></code></strong> is a special case as its value is not expected to be BER-encoded, so you can directly use a string for its value. </p> <p class="para"> When controls are parsed by <span class="function"><a href="function.ldap-parse-result.php" class="function">ldap_parse_result()</a></span>, values are turned into an array if supported. This is supported for: <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-passwordpolicyresponse">LDAP_CONTROL_PASSWORDPOLICYRESPONSE</a></code></strong> Keys are expire, grace, [error] </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-pagedresults">LDAP_CONTROL_PAGEDRESULTS</a></code></strong> Keys are size, cookie </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-pre-read">LDAP_CONTROL_PRE_READ</a></code></strong> Keys are dn and LDAP attributes names </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-post-read">LDAP_CONTROL_POST_READ</a></code></strong> Keys are dn and LDAP attributes names </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-sortresponse">LDAP_CONTROL_SORTRESPONSE</a></code></strong> Keys are errcode, [attribute] </p> </li> <li class="listitem"> <p class="para"> <strong><code><a href="ldap.constants.php#constant.ldap-control-vlvresponse">LDAP_CONTROL_VLVRESPONSE</a></code></strong> Keys are target, count, errcode, context </p> </li> </ul> </p> </div> <?php manual_footer($setup); ?>