Пример #1
0
<?php

require_once '../.env';
require_once '../src/LDAP.php';
require_once '../src/LDAPUser.php';
use mikebywater\LDAP\LDAP;
// include user object so we can use on the result
use mikebywater\LDAP\LDAPUser;
// Instantiate object
$ldap = new LDAP();
$username = "******";
// Method chaining allows us to bind to ldap, apply an ldap filter and get the first result
$entry = $ldap->bind()->filter("sAMAccountName={$username}")->get()->first();
//Instantiate the user object (requires us to pass a connection and person entry to the object)
$user = new LDAPUser($ldap->conn, $entry);
$name = $user->getName();
//special function for display name
$email = $user->getEmail();
//special function foe mail attributes
$company = $user->__get('company')[0];
// any other attribute can be grabbed with magic get method (beware will return an array)
$description = $user->__get('description')[0];
echo "Name :  {$name} <br/>";
echo "Email Address :  {$email} <br/>";
echo "Description :  {$description} <br/>";
echo "Company :  {$company} <br/>";
echo "Groups :";
echo "<ul>";
foreach ($user->getGroups() as $group) {
    echo "<li> {$group} </li>";
}
Пример #2
0
<?php

require_once '../.env';
require_once '../src/LDAP.php';
require_once '../src/LDAPUser.php';
use mikebywater\LDAP\LDAP;
use mikebywater\LDAP\LDAPUser;
//We are going to use the default filter so of (&(objectCategory=Person)(sAMAccountName=*) so we can ommit the filter method
// Add a filter method after the bind
$ldap = new LDAP();
$entry = $ldap->bind()->get()->first();
// we get the first entry then loop through
do {
    $user = new LDAPUser($ldap->conn, $entry);
    $name = $user->getName();
    $email = $user->getEmail();
    echo "<h3> {$name} </h3>";
    echo "<p> {$email} </p><hr/>";
} while ($entry = $ldap->get()->next());
//while you are still getting an entry returned the loop will continue
// as soon as $ldap->get()->next() does not return an entry the loop will end
Пример #3
0
<?php

require_once '../.env';
require_once '../src/LDAP.php';
require_once '../src/LDAPUser.php';
use mikebywater\LDAP\LDAP;
$ldap = new LDAP();
$username = '******';
$password = '******';
if ($ldap->authenticate($username, $password)) {
    echo "Authenticated";
} else {
    echo "Invalid Credentials";
}