1. Go to this page and download the library: Download hakuryo/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/ */
hakuryo / ldap-client example snippets
$ldap = ConnectionLDAP::fromFile("my_file",'ldap');
$res = $ldap->search(filter:"objectClass=person",trackBy:"mail");
print_r($res);
// Will ouptut something like this with uid= toto32 sn=toto and [email protected]
Array
(
["[email protected]"] => stdClass Object
(
[uid] => toto32
[sn] => toto
[mail] => [email protected]
)
)
use hakuryo\ldap\ConnectionLDAP;
// Basic connection
$ldap = new ConnectionLDAP("myldap.mydomain.com","uid=user,ou=people,dc=mydomain,dc=com")
// From File
$ldap = ConnectionLDAP::fromFile("path_to_my_ldap_ini_file");
// You can specify a section of your ini file
$ldap = ConnectionLDAP::fromFile("path_to_my_ldap_ini_file","ldap_section");
//ldap_search
$ldapFilter = "memberof=cn=admin,ou=groups,dc=mydomain,dc=com";
$attrList = ["uid","displayname","sn","givenname"];
$results = $ldap->search($ldapFilter,$attrList);
foreach($result as $entry){
echo json_encode($entry,JSON_PRETTY_PRINT);
}
// get an specifique entry
$ldap->getEntry($ldapFilter,$attrList);
// Modify serach_options
$ldap->getSearchOptions()->setBaseDN("ou=my_ou,dc=exemple,dc=com");
$ldap->getSearchOptions()->setResultLimit(1);
$ldap->getSearchOptions()->setScope(LdapSearchOptions::SEARCH_SCOPE_ONE_LEVEL);
// You can chain modification
$ldap->getSearchOptions()->setResultLimit(1)->setScope(LdapSearchOptions::SEARCH_SCOPE_ONE_LEVEL);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.