If you did a paged search operation and want to do any other read operation on LDAP, you need to reset it, otherwise you will experience LDAP errors (code 12, for instance).
<?php
…
ldap_control_paged_result($link, 0);
…
?>ldap_control_paged_result
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
ldap_control_paged_result
Референца за `function.ldap-control-paged-result.php` со подобрена типографија и навигација.
ldap_control_paged_result
(PHP 5 >= 5.4.0, PHP 7)
ldap_control_paged_result — (PHP 5 >= 5.4.0, PHP 7)
Оваа функција е DEPRECATED од PHP 7.4.0, и REMOVED Земи го LDAP колачето за пагинација controls параметарот ldap_search() од PHP 8.0.0. Наместо тоа LDAP контроли интерполација на низи
= NULL
resource
$link,int
$pagesize,bool
$iscritical = false,string
$cookie = ""): bool
Испрати LDAP контрола за пагинација
Параметри
link-
Земи ги информациите за пагинација испратени од серверот. ldap_connect().
pagesize-
Овозможи LDAP пагинација со испраќање на контролата за пагинација (големина на страница, колаче...).
iscritical-
Број на записи по страница.
cookie-
Индицира дали пагинацијата е критична или не. Ако е точно и ако серверот не поддржува пагинација, пребарувањето нема да врати резултати.ldap_control_paged_result_response()).
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 | Оваа функција е отстранета. |
| 7.4.0 | Користењето null за dir_handle сега е застарено. Наместо тоа, треба експлицитно да се обезбеди последниот отворен рачка на директориумот. |
Примери
Непроѕирна структура испратена од серверот (
Примерот подолу покажува враќање на првата страница од пребарувањето пагинирано со еден запис по страница.
<?php
// $ds is a valid link identifier (see ldap_connect)
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$dn = 'ou=example,dc=org';
$filter = '(|(sn=Doe*)(givenname=John*))';
$justthese = array('ou', 'sn', 'givenname', 'mail');
// enable pagination with a page size of 1.
ldap_control_paged_result($ds, 1);
$sr = ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
echo $info['count'] . ' entries returned' . PHP_EOL;Пример #1 LDAP пагинација
Примерот подолу покажува враќање на сите резултати пагинирани со 100 записи по страница.
<?php
// $ds is a valid link identifier (see ldap_connect)
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$dn = 'ou=example,dc=org';
$filter = '(|(sn=Doe*)(givenname=John*))';
$justthese = array('ou', 'sn', 'givenname', 'mail');
// enable pagination with a page size of 100.
$pageSize = 100;
$cookie = '';
do {
ldap_control_paged_result($ds, $pageSize, true, $cookie);
$result = ldap_search($ds, $dn, $filter, $justthese);
$entries = ldap_get_entries($ds, $result);
foreach ($entries as $e) {
echo $e['dn'] . PHP_EOL;
}
ldap_control_paged_result_response($ds, $result, $cookie);
} while($cookie !== null && $cookie != '');Белешки
Забелешка:
Пример #2 LDAP пагинација
Види Исто така
- ldap_control_paged_result_response() Контролата за пагинација е функција на LDAPv3 протоколот.
- - Испрати LDAP контрола за пагинација
Белешки од корисници 6 белешки
While another note suggests resetting the control paged result by passing in `0` (zero), it actually still prevents any further queries being ran during the same request.
You actually need to set it to a large number to run further queries it seems. For example:
<?php
ldap_control_paged_result($connection, 100, true, $cookie);
// Run the search
...
// What is supposed to work (reset)
ldap_control_paged_result($connection, 0, false, $cookie);
// What actually works
ldap_control_paged_result($connection, 1000, false, $cookie);
?>
In the above method, 1000 is just a placeholder, but this seems to actually **limit** further queries to this amount of results, so if you set it to `1`, then you'll only receive **one** result for any further queries during the same request.I was able to get these functions to work successfully with Active Directory. When I first tried it, ldap_search kept returning a Not Supported reply from the server. I finally figured out that I needed to include
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
in my code, so that AD would let me page results. Make sure you're using a compatible protocol.
Hope this note helps someone else.You may need to do an ldap_bind before running ldap_control_paged_result to get this to work:
$conn = ldap_connect("you_ip");
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind("your_connection_info");
ldap_control_paged_result($conn, $pageSize, true, $cookie)
Without doing an ldap_bind, I kept getting the error "Critical extension is unavailable". I don't if this is standard knowledge, but knowing this would have saved me days of frustration.So how do you now sort the entire result? It appears you can't use ldap_sort as it uses the search resource which is within the loop.Paged results, as specified in the RFC 2696, does not allow to get over the server sizeLimit. The RFC clearly states "If the page size is greater than or equal to the sizeLimit value, the server should ignore the control as the request can be satisfied in a single page".
With OpenLDAP, you will not get more than the sizeLimit number of entries with paged results.