PHP code example of stepansib / ldap

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

    

stepansib / ldap example snippets


use StepanSib\LDAP\LDAP;

$ldap = new LDAP2(array(
    'host' => 'server.company.com',
    'username' => 'johndoe',
    'password' => '12345',
    'domain' => 'Company',
    'base_dn' => 'DC=Company,DC=com',
    'anonymous' => false,               // Optional parameter
    'can_login_via_shortname' => true,  // Optional parameter, set to false if your LDAP instance 

$ldap->connect();

$ldap->authenticate("jdoe", "12345");
$ldap->authenticate("[email protected]", "12345");
$ldap->authenticate("John Doe", "12345");

$filter = '(memberOf=CN=Company Management,CN=Users,DC=Company,DC=com)';
//$filter = '&(objectClass=user)(sAMAccountName=jdoe))'; // any valid filter can be passed
$baseDn = 'DC=Company,DC=com';

$data = $ldap->search(
    $filter,
    array(
        'cn',
        'distinguishedname',
        'displayname',
        'department',
        'title',
        'sAMAccountName',
        'mail',
        'displayName'
    ),
    $baseDn,
);

$ldap->close();