请查看此处的代码:http://pastebin.com/ZLHG6m07
这段代码正在工作,它绑定到ldap服务器,代码询问用户的"用户名"answers"密码"进行二次绑定,并搜索一个数组。使用用户的CN,我搜索并创建一个数组,提取DN。问题是,我不知道如何从数组中提取完整的DN,并将其正确地放回变量中,这样我就可以与该用户绑定并验证ldap。具体来说,我正在处理这部分代码,它没有正确地将[dn]放入$distinguishedName变量:
$ldapCount = @ldap_count_entries($ldapConnection, $ldapSearch);
if (!$ldapCount) {
die('account not found');
} else {
if (!$ldapEntry = @ldap_get_entries($ldapConnection, $ldapSearch)) {
die('Could not get ldap entry');
}
$distinguishedName = $ldapEntry[0]['dn'][0];
print_r($ldapEntry);
if (empty($distinguishedName)) {
die('Account information not found');
}
if(!@ldap_bind($ldapConnection, $distinguishedName, $_POST['password']))
dn
条目不包含数组,而是直接包含DN条目。所以你的代码应该是这样的:
$distinguishedName = $ldapEntry[0]['dn'];
我创建了一个小要点来说明LDAP登录https://gist.github.com/heiglandreas/5689592.请特别查看第68行