Skip to content

Core\Ldap\Filter::atMost

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

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

LDAP has no "less than" filter. To find values less than 5, combine Core\Ldap\Filter::not with Core\Ldap\Filter::atLeast 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

Locked after few attempts

<?nvs
// Shows how to find the accounts with three wrong passwords or fewer.
var $filter = Core\Ldap\Filter::atMost('badPwdCount', '3');
// This prints (badPwdCount<=3).
echo $filter->toString(), "\n";
Output
(badPwdCount<=3)

Less than

<?nvs
// Shows how to write "less than", which LDAP does not have.
// Less than 100 is the same as "not at least 100".
var $filter = Core\Ldap\Filter::not(Core\Ldap\Filter::atLeast('uSNChanged', '100'));
// This prints (!(uSNChanged>=100)).
echo $filter->toString(), "\n";
Output
(!(uSNChanged>=100))

Names up to a letter

<?nvs
// Shows how to split a list of people into two halves by the first letter of their name.
var $firstHalf = Core\Ldap\Filter::atMost('sn', 'M');
var $secondHalf = Core\Ldap\Filter::not($firstHalf);
// For text, the order is alphabetical. These print (sn<=M) and (!(sn<=M)).
echo $firstHalf->toString(), "\n";
echo $secondHalf->toString(), "\n";
Output
(sn<=M)
(!(sn<=M))