1. Go to this page and download the library: Download erwin32/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/ */
erwin32 / ldap example snippets
// Active Directory server
$ldap_host = "123.123.123.123";//IP adress or url
// Active Directory DN
$ldap_dn = 'DC=domain,DC=com';//domain in this example is used "domain.com"
// Active Directory user group
$ldap_user_group = "Group Name";
// Active Directory manager group
$ldap_manager_group = "Admins";
// Domain, for purposes of constructing $user
$ldap_usr_dom = "@domain.com";
//class inicialization
$ldap=new \LDAP\auth($ldap_host, $ldap_dn, $ldap_user_group, $ldap_manager_group, $ldap_usr_dom);
try {
$ldap->authenticate($user, $pass);
} catch (Exception $exc) {
$msg=$exc->getMessage();
$code=$exc->getCode();
//this is how we can determine if user dont have corect group but exist on LDAP
if($ldap::ERROR_WRONG_USER_GROUP==$code){
//custom handling
}
}
try {
$ldap->userInit($user, $pass);
//we can display it like this
echo '<img src="'.$ldap->getLDAPimg().'">';
} catch (Exception $exc) {
$msg=$exc->getMessage();
$code=$exc->getCode();
//react to problems
}