zendframework/zend-ldap
Zend LDAP provides PHP tools for LDAP directory operations like binding, searching, and modifying entries. This repository was abandoned on 2019-12-31 and has moved to laminas/laminas-ldap.
composer require zendframework/zend-ldap
Ldap instance with connection and bind options:
use Zend\Ldap\Ldap;
$ldap = new Ldap([
'host' => 'ldap.example.com',
'port' => 389,
'useStartTls' => true,
'bindRequiresDn' => true,
'baseDn' => 'DC=example,DC=com',
'username' => 'admin@example.com',
'password' => 'secret',
]);
authenticate():
try {
$ldap->authenticate('cn=John Doe,OU=Users,DC=example,DC=com', 'userPassword123');
// Authenticated successfully
} catch (\Zend\Ldap\Exception\LdapException $e) {
// Handle failure (e.g., invalid credentials)
}
Auth::viaCallback() or custom UserProvider). Cache.Bind DN resolution separately (e.g., look up user DN first via getCanonicalAccountName() + getAccountCanonicalName()).$users = $ldap->getLdap()->search(
'(sAMAccountName=jdoe)',
'OU=Users,DC=example,DC=com',
Ldap::SEARCH_SCOPE_SUB
);
Use getAttributeValues() or getAttributeValue() for attribute access (handles single/multi-valued safely).baseDn, username, and password per tenant; avoid hard-coding credentials.Zend\Ldap\Attribute\Group and Zend\Ldap\Attribute\User to normalize AD vs. OpenLDAP differences (e.g., member vs. memberUid, objectClass values).add(), modify(), delete() with DN utilities (Ldap::BUILD_DN_*) to prevent injection or malformed DNs.bindRequiresDn = true is common in AD; set it explicitly. Otherwise, username may be interpreted as a simple username (e.g., jdoe) vs. full DN (cn=John Doe,...).Ldap::escapeFilter($input) or Ldap::escapeValue($input) to avoid injection and broken queries.useSsl opens LDAPS (port 636); useStartTls starts unencrypted and upgrades. Mix-ups cause timeout/no-reponse issues (common in Docker/containers without host network).pageSize in config to avoid sizelimit exceeded errors on large directories.Zend\Logger integration or catch LdapException and inspect getLdapErrorMessage() (returns extended LDAP error codes + descriptions).getAdapter()->getResource() to access raw LDAP connection for custom operations (e.g., ldap_get_option()).laminas/* over zendframework/* to avoid conflicts.How can I help you explore Laravel packages today?