PHPackages                             gozoro/ldap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gozoro/ldap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gozoro/ldap
===========

A simple PHP class for getting user data from Active Directory.

v2.0.3(6mo ago)015MITPHPPHP &gt;=5.5.9

Since Jul 13Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/gozoro/ldap)[ Packagist](https://packagist.org/packages/gozoro/ldap)[ Docs](https://github.com/gozoro/ldap)[ RSS](/packages/gozoro-ldap/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (6)Used By (0)

ldap
====

[](#ldap)

A simple tool for getting user data from Active Directory.

Installation
------------

[](#installation)

```
	composer require gozoro/ldap

```

Configuration
-------------

[](#configuration)

- **username** - service username to bind.
- **password** - service password to bind.
- **hosts** - array of ldap-server hosts.
- **domainName** - domain name, for example "example.net".
- **dnsSuffixes** - here you can specify additional dns suffixes for complex domains.
- **timeout** - sets timeout to the `LDAP_OPT_NETWORK_TIMEOUT` option.
- **protocolVersion** - sets protocol version (2 or 3) to LDAP\_OPT\_PROTOCOL\_VERSION option. By default version: 3.
- **beforeConnect** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **afterConnect** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **beforeClose** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **afterClose** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **beforeSearch** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **afterSearch** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **beforeValidatePassword** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **afterValidatePassword** - the event handler function for example `function(Ldap $ldap){ ... }`.
- **starttls** - start TLS after connect to LDAP-server.
- **SASL\_MECH** - here you can set SASL mechanism. For example: `GSSAPI`,`DIGEST-MD5`, etc. By default - empty string SALS is disabled. [SASL](https://en.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer) - Simple Authentication and Security Layer.
- **SASL\_PASS\_MECH** - the SASL mechanism for validating the user password when using SASL. By default DIGEST-MD5.
- **SASL\_REALM** - the realm when using SASL. If realm undefind then realm sets from 'domainName'.

#### Popular SASL mechanisms

[](#popular-sasl-mechanisms)

- [NTLM](https://en.wikipedia.org/wiki/NTLM) - an NT LAN Manager authentication mechanism.
- [GSSAPI](https://en.wikipedia.org/wiki/GSSAPI) - The Generic Security Service Application Program Interface is an application programming interface for programs to access security services. It is used for Kerberos V5 authentication via the GSSAPI.
- [DIGEST-MD5](https://en.wikipedia.org/wiki/Digest_access_authentication) - Digest access authentication
- etc

Usage
-----

[](#usage)

```
$config = [
	'username'   => 'admin',
	'password'   => '12345',
	'hosts'      => ['ldap1.example.net', 'ldap2.example.net'],
	'domainName' => 'example.net',
];

$ldap = new \gozoro\ldap\Ldap($config);

$user = $ldap->findUser('john');

print $user->getPrincipalName(); // john@example.net
print $user->getDisplayName();   // John Smith
print $user->getLastLogonTime(); // 2020-07-12 14:23:17
print $user->getObjectGuid();    // 1ba5b8ff-b80b-40d4-ae45-7418f8eedd6a
print_r($user->getGroupNames()); // Array(0=>'admins', 'users')

$userPassword = 'qwerty';

if($user->validatePassword($userPassword))
{
	print 'password: OK';
}

foreach($user->getGroups() as $userGroup)
{
	print $userGroup->getName();
	print $userGroup->getObjectGUID();
}
```

Usage with SASL
---------------

[](#usage-with-sasl)

```
$config = [
	'hosts'      => ['ldap1.example.net', 'ldap2.example.net'],
	'domainName' => 'example.net',
	'protocolVersion' => 3,

	'SASL_MECH'      => 'GSSAPI',     // Kerberos v5
	'SASL_PASS_MECH' => 'DIGEST-MD5', // mechanism of validating user's password
	'SASL_REALM'     => 'example.net'

	'beforeConnect' => function($ldap){
		$cmd = "kinit -k -t /etc/keytabs/my.access.keytab ldap/example.net@EXAMPLE.NET 2>&1";
		exec($cmd, $output, $result);
		if ($result !== 0) {
			throw new \Exception("kinit failed: " . implode("\n", $output));
		}
	},

	'afterDisconnect' => function(){
		$cmd = "kdestroy 2>&1";
		exec($cmd, $output, $result);
		if ($result !== 0) {
			throw new \Exception("kdestroy failed: " . implode("\n", $output));
		}
	},
];

// Authentication with SASL mechanism GSSAPI (Kerberos v5)
$ldap = new \gozoro\ldap\Ldap($config);

if($ldap->validatePassword('john', 'qwerty'))
{
	print 'password: OK';
}
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~493 days

Total

5

Last Release

208d ago

Major Versions

v1.0.1 → v2.0.12025-11-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/a273abe77cdd4c74270a90320efbeb4d4dfb3ceac5b4d505ce2ccafddf1e06e0?d=identicon)[gozoro](/maintainers/gozoro)

---

Top Contributors

[![gozoro](https://avatars.githubusercontent.com/u/13768280?v=4)](https://github.com/gozoro "gozoro (14 commits)")

---

Tags

ldapactive directoryactivedirectory

### Embed Badge

![Health badge](/badges/gozoro-ldap/health.svg)

```
[![Health](https://phpackages.com/badges/gozoro-ldap/health.svg)](https://phpackages.com/packages/gozoro-ldap)
```

###  Alternatives

[symfony/ldap

Provides a LDAP client for PHP on top of PHP's ldap extension

1408.1M59](/packages/symfony-ldap)[adldap/adldap

A PHP LDAP Library for Active Directory Manipulation

424171.8k9](/packages/adldap-adldap)[ldaptools/ldaptools

LdapTools is a feature-rich LDAP library for PHP 5.6+.

205268.8k1](/packages/ldaptools-ldaptools)[freedsx/ldap

A Pure PHP LDAP library

157150.3k2](/packages/freedsx-ldap)[avadaneidanut/ldapquery

A light weight package for easily building LDAP advanced filter queries.

4718.5k](/packages/avadaneidanut-ldapquery)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
