Table of Contents
Read user attributes
Use the username or an email address to get user data. The 2nd parameter defines the attributes to fetch (["*"]
is default).
$aUser = $oLdap->getUserInfo("john@example.com", []);
$aUser = $oLdap->getUserInfo("john@example.com", ["memberof", "uid"]);
// simplify result array:
print_r($oLdap->normalizeSearchentry($aUser));
Verify user and password for login
// set values from $_FORM or $_POST data of your login form here
// The variable $bAuthenticated is true if authentication of the user was successful.
$bAuthenticated=oLdap->verifyPassword($sUser, $sPassword);
Search
When using special chars in search then you can sanitize the search string.
$sCn = 'John Smith (john)';
$sSearchFilter = '(cn='.$oLdap->sanitizeFilter($sCn).')';
$aResults = $oLdap->searchDn("<DN here>", $sSearchFilter, ["*"]);
$oLdap->close();
Debugging
If you want to find connection problems then use debugOn(). This enables the echoing of ldap actions for connect, bind and class internal debug messages.
$oLdap = new imlldap($aConfig);
// enable showing debug output
// This method sets LDAP_OPT_DEBUG_LEVEL to $aConfig['debugLevel'];
$oLdap->debugOn();
// then do something ... the first action will conect and bind
if ($oLdap->objectAttributeAndValueExist($sDn, $sAttribute, $sMemberDN)) {
...
}