PHP code example of mathermann / php-ldap-client

1. Go to this page and download the library: Download mathermann/php-ldap-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mathermann / php-ldap-client example snippets




atHermann\Ldap\Exception\LdapException;
use MatHermann\Ldap\LdapClient;

try {
    $host = '127.0.0.1';
    $port = 389;
    $dn = 'DC=yourDomain,DC=com';
    $OU = 'yourOrganizationalUnit';

    $username = 'yourUsername';
    $password = 'yourPassword';

    $client = new LdapClient($host, $port, $dn);

    $user = $client->signInUser($username, $password, "OU=$OU");

    var_dump($user); // Access user properties with $user->get('property')

} catch (LdapException $exception) {
    var_dump($exception); // Handle LDAP exceptions
}