array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), '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 => '示例', ), '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); ?>
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.
注意:
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=*).
示例 #1 Testing support for paged result control
<?php
// $ds is a valid link identifier for a directory server
$result = ldap_read($ds, '', '(objectClass=*)', ['supportedControl']);
if (!in_array(LDAP_CONTROL_PAGEDRESULTS, ldap_get_entries($ds, $result)[0]['supportedcontrol'])) {
die("This server does not support paged result control");
}
?>
As of PHP 7.3, you can send controls with your request in all
request functions using the controls
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 ldap_parse_result().
controls
must be an array containing an array for each control to send,
containing the following keys:
false
.
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:
LDAP_CONTROL_PAGEDRESULTS
Expected keys are [size] and [cookie]
LDAP_CONTROL_ASSERT
Expected key is filter
LDAP_CONTROL_VALUESRETURNFILTER
Expected key is filter
LDAP_CONTROL_PRE_READ
Expected key is attrs
LDAP_CONTROL_POST_READ
Expected key is attrs
LDAP_CONTROL_SORTREQUEST
Expects an array of arrays with keys attr, [oid], [reverse].
LDAP_CONTROL_VLVREQUEST
Expected keys are before, after, attrvalue|(offset, count), [context]
The following controls do not need any value:
The control LDAP_CONTROL_PROXY_AUTHZ
is a special case
as its value is not expected to be BER-encoded, so you can directly
use a string for its value.
When controls are parsed by ldap_parse_result(), values are turned into an array if supported. This is supported for:
LDAP_CONTROL_PASSWORDPOLICYRESPONSE
Keys are expire, grace, [error]
LDAP_CONTROL_PAGEDRESULTS
Keys are size, cookie
LDAP_CONTROL_PRE_READ
Keys are dn and LDAP attributes names
LDAP_CONTROL_POST_READ
Keys are dn and LDAP attributes names
LDAP_CONTROL_SORTRESPONSE
Keys are errcode, [attribute]
LDAP_CONTROL_VLVRESPONSE
Keys are target, count, errcode, context