Hi this has been going around a little but hopefully I can get some light shone on the problem. Basically I would like to do a search in my active directory using ldap and paginate the results.
I've seen code like this around but it doesn't make any sense to me
// $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 != '');
What does this actually do? What is the cookie all about?
I could replace
$result = ldap_search($ds, $dn, $filter, $justthese);
with
$result = ldap_search($ds, $dn, $filter, $justthese,0,100);
Which would do with filter and get me the first 100 rows.
The question in hand is how do I control ldap pagination successfully. i.e giving the number of results to return and the page that I want them from.
Update
Right the code above, I've given it a run and what it does is run the search, several times - returning in each iteration a new page until the end. So it seems that the cookie has some control over that.