PHP code example of jstormes / ldap
1. Go to this page and download the library: Download jstormes/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/ */
jstormes / ldap example snippets
use JStormes\Ldap\Connector\Connector;
use JStormes\Ldap\LdapAdapter\LdapAdapter;
use JStormes\Ldap\SchemaAdapter\SchemaAdapterOpenLDAP as SchemaAdapter;
use Psr\Log\NullLogger;
$serverString = "LOOPBACK:us.loopback.world:DC=us,DC=loopback,DC=world";
$ldapAdapter = new LdapAdapter();
$schemaAdapter = new SchemaAdapter($serverString);
$logger = new NullLogger();
$connector = new Connector($ldapAdapter, $schemaAdapter, $logger);
$username = 'testUser';
$password = 'test';
$isConnected = $connector->connect($username, $password);
$user = $connector->getUserEntity();
$userName = $user->getUserName();
$dispalyName = $user->getDisplayName();
$email = $user->getEmailAddress();
$groups = $user->getUserGroups();