Other methods

Checking if an Entry is Active

Sometimes, you might have entries in your directory that have expired accounts. To check if they are active or not, you can use the isActive() method.

Note

if you have specified the attributes to return, then you must include the attribute used in the directory for the expiry timestamp. For example, accountexpires. You also must sure that the attribute is identified using the setAccountExpiresAttribute() method.

The default is accountexpires.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
$attribs = [
    'cn',
    'accountexpires',
    'sn',
    'email',
    'displayname'
];

// If you don't specify $attribs, all available are returned
$row = $ldap->findOneByUserid('juser', $attribs);

if ($ldap->isActive($row)) {
    ...    
}

// Specifying the account expires attribute
$ldap->setAccountExpiresAttribute('expires');

$attribs = [
    'cn',
    'expires',
    'sn',
    'email',
    'displayname'
];

$row = $ldap->findOneByUserid('juser', $attribs);

if ($ldap->isActive($row)) {
    ...    
}

By default, the isActive() method assumes the timestamp is in the 18-digit, Windows NT timestamp format. You can change this to a YYYYMMDDHHIISSZ format as needed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
// Allowed timestamp formats are 'winnt' and 'ymd'

$ldap->setTimestampFormat('ymd');

$row = $ldap->findOneByUserid('juser', $attribs);

if ($ldap->isActive($row)) {
    ...    
}

Sorting

You can sort the results from a findAll() or findAllBy() method call. You must set the sortBy attribute before calling the findAll() method.

Warning

This method is DEPRECIATED as of PHP 7. Use at your own risk.

1
2
3
<?php
$ldap->setSortBy('givenName');
$rows = $ldap->findAllByLastname('El*');

Note

The sortBy value is reset after the findAll() or findAllBy() methods.

Other Stuff of Note

The find() and findAll() methods perform NO escaping on the search filter passed to the method. It's up to you to make sure the values don't contain bad characters.

The findOneBy...() and findAllBy...() methods DO escape the value passed to the search. The escape is done using the PHP function addcslashes(). The default escape characters are:

1
2
<?php
protected $escapeChars = '\\&!|=<>,+-"\';()';

You can change those using the setEscapeChars() method.