PHPerKaigi 2024


(PHP 5 >= 5.4.0, PHP 7)

ldap_control_paged_resultEnvoi un contrôle de pagination LDAP


Cette fonction est OBSOLÈTE à partir de PHP 7.4.0, et SUPPRIMÉE à partir de PHP 8.0.0. À la place le paramètre controls de ldap_search() devrait être utilisée. Voir les Contrôles LDAP pour plus d'information.


    resource $link,
    int $pagesize,
    bool $iscritical = false,
    string $cookie = ""
): bool

Active la pagination LDAP en envoyant le contrôle de pagination (taille de la page, cookie,...).

Liste de paramètres


Une ressource LDAP, retourné par ldap_connect().


Le nombre d'entrées par page.


Indique si la pagination est critique ou non. Si vaut true, et si le serveur ne supporte pas la pagination, la recherche ne retournera aucun résultat.


Une structure opaque envoyée par le serveur (ldap_control_paged_result_response()).

Valeurs de retour

Cette fonction retourne true en cas de succès ou false si une erreur survient.


Version Description
8.0.0 Cette fonction a été supprimée.
7.4.0 Cette fonction est devenue obsolète.


L'exemple ci-dessous montre la manière pour récupérer la première page d'une recherche paginée avec une seule entrée par page.

Exemple #1 Pagination LDAP

// $ds est un identifiant de lien valide (voir 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');

// active la pagination avec une taille de page à 1.
ldap_control_paged_result($ds, 1);

$sr = ldap_search($ds, $dn, $filter, $justthese);

$info = ldap_get_entries($ds, $sr);

$info['count'] . ' entrées retournées' . PHP_EOL;

L'exemple ci-dessous montre la manière pour récupérer tous les résultats paginés avec 100 entrées par page.

Exemple #2 Pagination LDAP

// $ds est un identifiant de lien valide (voir 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');

// active la pagination avec une taille de page à 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) {
$e['dn'] . PHP_EOL;

ldap_control_paged_result_response($ds, $result, $cookie);

} while(
$cookie !== null && $cookie != '');



Le contrôle de la pagination est une fonctionnalité du protocole LDAPv3.

add a note

User Contributed Notes 6 notes

10 years ago
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).


($link, 0);

steven_bauman at outlook dot com
7 years ago
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:

($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.
11 years ago
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.
jestertrance at hotmail dot com
10 years ago
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_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.
dublue at gmail dot com
9 years ago
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.
etienne at lamaisondebarbie dot ch
11 years ago
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.
To Top