Returned 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

<?php
// These will be used on all find methods
$default_attribs = [
    'cn',
    'sn',
    'displayName',
    'mail',
    'l'
];

$ldap->setDefaultAttributes($default_attribs);

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

// $rows will return an array of rows (array) with the
// default attributes as keys + dn

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

<?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.

<?php
// Use these aliases
$aliases = [
    'sn'=>'surname',
    'l'=>'locality'
];

$ldap->setAttributeAliases($aliases);

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