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
.
<?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.
<?php
// Allowed timestamp formats are 'winnt' and 'ymd'
$ldap->setTimestampFormat('ymd');
$row = $ldap->findOneByUserid('juser', $attribs);
if ($ldap->isActive($row)) {
...
}
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:
<?php
protected $escapeChars = '\\&!|=<>,+-"\';()';
You can change those using the setEscapeChars()
method.