ldap_search Not returning more than 1000 user

7.2k Views Asked by At

ldap_search Not returning more than 1000 user. I have also set the sizelimit to 0. Let me the know the solution.

2

There are 2 best solutions below

0
On

Read PHP ldap_search size limit exceeded for more details.

Alternatively, try to use following code

// Verbindung mit dem LDAP-Server herstellen
$ldap_connect = ldap_connect($ldap_host) or die( "Could not connect!" );
// Beim LDAP-Server authentifizieren
ldap_set_option($ldap_connect, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");
ldap_set_option($ldap_connect, LDAP_OPT_REFERRALS, 0); 
ldap_set_option($ldap_connect, LDAP_OPT_SIZELIMIT, 33);  
$ldap_bind_anonym = ldap_bind($ldap_connect, "*************", "*************");
$filter = "objectclass=group";
$attrb = array("cn");
$ldap_search = ldap_search($ldap_connect, $base_dn, $filter, $attrb, 0, 0) or die ("Could not search!"); 
$ldap_result = ldap_get_entries($ldap_connect, $ldap_search);
$counter = 0;
foreach ($ldap_result AS $key => $ldap_value) {
   echo $ldap_value["cn"][0]."<br>";
   $counter++;
}
echo $counter;

Source: http://www.administrator.de/forum/ldap-search-mit-php-mehr-als-1000-eintr%C3%A4ge-95576.html

1
On

This solution works only for php version >5.4.

EDIT: as @derhansen mentioned, ldap_control_paged_result_response is deprecated since PHP 7.4

It brings a given number of results at once until there is data available.

 $ldap = ldap_connect($adServer, $adPort);
 $bind = ldap_bind($ldap, $username, $password);

// enable pagination with a page size of 100.
    $pageSize = 100;

    $cookie = '';
    $i=1;
    do {
        ldap_control_paged_result($ldap, $pageSize, true, $cookie);
        $filter = '(objectCategory=group)';
        $result  = ldap_search($ldap, "dc=SOMETHING,dc=COM", $filter);
        $entries = ldap_get_entries($ldap, $result);

        array_shift($entries);
        foreach ($entries as $e) {
            echo '<br>';
            echo $i. '. '. $e['dn'] . PHP_EOL;
            echo '<br> Name: '. $e['name'][0] . PHP_EOL;
            $i++;
        }

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

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

Hope this helps.

You can find more info here: http://php.net/manual/en/function.ldap-control-paged-result.php