Attributes

Specify Attributes Returned

If you do not specify what attributes you want returned, all attributes for a given user will be returned. You can specify the returned attributes either by setting default attributes, or by passing an array of attributes to the various find methods.

The user's dn is always returned.

Specify default attributes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php
// These will be used on all find methods
$default_attribs = [
    'cn',
    'sn',
    'displayName',
    'mail',
    'l'
];

$ldap->setDefaultAttributes($default_attribs);

$rows = $ldap->findAllByLastname('Smith');

Specify attributes for a given find method. These override default attributes, if set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<?php
$searchfilter = 'locality=Edmonton';
$attributes = [
    'cn',
    'fullname',
    'locality'
    'email'
];
$rows = $ldap->findAll($searchfilter, $attributes);

// The result will return an array with only those attributes, plus the DN for the user.

Using Attribute Aliases

The directory may use attributes are not all that meaningful. In these cases, you can set aliases to use instead of those used in the directory. Use a key to match the directory attribute and the value as the alias.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<?php
// Use these aliases
$aliases = [
    'sn'=>'surname',
    'l'=>'locality'
];

$ldap->setAttributeAliases($aliases);

$searchfilter = 'cn=juser';
$row = $ldap->find($searchfilter);