Skip to content

Core\Ldap\Filter::atLeast

Builds a filter that finds the directory entries where a value of an attribute is equal to or greater than this value.

The server compares by the attribute's own order. For a number, 10 is greater than 9. For a time, a later time is greater. For text, the order is alphabetical. The value is sent as data, so it may come from a form.

LDAP has no "greater than" filter. To find values greater than 5, combine Core\Ldap\Filter::not with Core\Ldap\Filter::atMost and the value 5.

A name with a character that an attribute name cannot have throws a LogicError.

Good to know: some attributes have no order at all. For those, the server finds nothing.

Parameters

  • $attributestringThe attribute's name, such as sAMAccountName. It cannot be tainted.
  • $valuestringThe value to compare with. It may be tainted. The server compares by the attribute's own order, so '10' comes after '9' for a number.

Return value

Returns Core\Ldap\Filter. A Core\Ldap\Filter.

Errors

  • LogicError$attribute is not an attribute name.

Examples

Changed since the last sync

<?nvs
// Shows how to find the entries that changed since a number you saved last time.
int $lastSeen = 41250;
// `uSNChanged` grows by one each time the server changes an entry.
var $filter = Core\Ldap\Filter::atLeast('uSNChanged', ($lastSeen + 1) as string);
// This prints (uSNChanged>=41251).
echo $filter->toString(), "\n";
Output
(uSNChanged>=41251)

Greater than

<?nvs
// Shows how to write "greater than", which LDAP does not have.
// Greater than 5 is the same as "not at most 5".
var $filter = Core\Ldap\Filter::not(Core\Ldap\Filter::atMost('badPwdCount', '5'));
// This prints (!(badPwdCount<=5)).
echo $filter->toString(), "\n";
// And "at least 6" finds the same whole numbers.
echo Core\Ldap\Filter::atLeast('badPwdCount', '6')->toString(), "\n";
Output
(!(badPwdCount<=5))
(badPwdCount>=6)

A range of values

<?nvs
// Shows how to find the values between two limits, both limits included.
var $filter = Core\Ldap\Filter::all(
Core\Ldap\Filter::atLeast('employeeNumber', '1000'),
Core\Ldap\Filter::atMost('employeeNumber', '1999'),
);
// This prints (&(employeeNumber>=1000)(employeeNumber<=1999)).
echo $filter->toString(), "\n";
Output
(&(employeeNumber>=1000)(employeeNumber<=1999))