Usage

Include the ldap class

require_once '[APPROOT]/classes/ldap.class.php';

Create a config with connection data

As an example I create a hash named $aConfig and save it as “inc_config.php”.

return [
    ...
    'ldap-master' => [
        'server'     => 'ldaps://ldap.example.com',
        'DnLdapUser' => 'cn=Lookup,ou=Service,dc=some,dc=example.com',
        'PwLdapUser' => 'PasswordOfLookupUser',

        // See Configuration page for all values.
    ],
    ...
];

Initialize connection

$aConfig = require_once('inc_config.php');
require_once '[APPROOT]/classes/ldap.class.php';

$oLdap=new imlldap($aConfig['ldap-maser']);

Methods

LDAP Connection

You can reconfigure the connetction data of a current ldap object:

  • setConfig(array $aConfig = []): void
    Set new connection values.

These methods are used internally - it is not a must to use them:

  • connect(): void
    Connect to host and port
  • bind(string $sUser = ‘’, string $sPw = ‘’): bool
    with bind a user and password to access ldap data
  • unbind(): void

Object handling

  • DnExists(string $sDn): bool
    Check if a DN exists
  • objAdd(string $sDn, array $aItem): bool
    Create a new object
  • objGet(string $sDn, string $sSearchFilter = ‘(objectclass=*)’, array $aAttributesToGet = [“*“]): bool|array
    Get object data of a given DN
  • objUpdate(string $sDn, array $aItem): bool
    Update values of a given object
  • objDelete(string $sDn): bool
    Delete an object

Attributes

  • objAddAttr(string $sDn, array $aItem): bool
  • objDeleteAttr(string $sDn, array $aItem): bool
  • objectAttributeExists(string $sDn, string $sAttribute): bool
    Check if an attribute exists
  • objectAttributeAndValueExist(string $sDn, string $sAttribute, string $sAttrValue): bool
    Check if an attribute exists and has a given value
  • objectAttributeAndValueMustExist(string $sDn, string $sAttribute, string $sAttrValue): bool
    Force the existence of an attribute that must have a given value

User functions

You need to set $aConfig['DnUserNode'] to a base DN where are the user objects.

  • userAdd(array $aItem, string $sDn = “”)
  • getUserInfo(string $sUser, array $aAttributesToGet = [“*“]): bool|array
  • userDelete(string $sUserDn)
  • userUpdate(array $aItem)
  • setPassword(string $sUser, string $sPW): bool
  • verifyPassword(string $sUser, string $sPW): bool

Debugging

Turn debugging on or off.

  • debugOff()
  • debugOn()