PHP code example of rimelek / ldap-client

1. Go to this page and download the library: Download rimelek/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/ */

    

rimelek / ldap-client example snippets


use Rimelek\LDAPCLient\LDAP;
   
$ldap = new LDAP();
$ldap->setServer('ldap.domain.tld');
$ldap->setPort(389);  // optional. Default: 389
   
$ldap->setManagerDn('uid=' . $user->getUsername() . ',ou=people,dc=domain,dc=tld');
$ldap->setPassword($user->getPassword());

$ldap->setScope(LDAP::SCOPE_SUB); // for search (*_ONE | *_BASE | *_SUB)
$ldap->setBaseDn('ou=people,dc=domain,dc=tld'); // for search

use Rimelek\LDAPClient\Filter;
use Rimelek\LDAPClient\OrFIlter;
use Rimelek\LDAPClient\AndFilter;

/*Simplest filter:*/ $filter = new Filter('key', 'value');
/*Multiple filters:*/
  /*or:*/ 
  
  $filter = new OrFilter([
      new Filter('key1', 'value1'),
      new Filter('key2', 'value2', Filter::OP_GREATER_THAN),
  ]);
  
  /*and:*/
  
  $filter = new AndFilter([
      new Filter('key1', 'value1'),
      new Filter('key2', 'value2', Filter::OP_GREATER_THAN),
  ]);
  
/* You can also negate it: */
  
  $filter = new AndFilter([
      new Filter('key1', 'value1'),
      new Filter('key2', 'value2', Filter::OP_GREATER_THAN),
  ], true);

$result = $ldap->search($filter);
$entries = $result->getEntries();
   
foreach ($entries as $entry) {
    $attr = $entry->getAttribute();
    echo $attr->getName() . '<br />';
    foreach ($attr as $value) {
        echo  ' - ' . $value . '<br />';   
    }
}
bash
php composer.phar