我的 ldap 连接有问题.
I have a problem with ldap connection.
$hostname="ldap://sub.domain.com";
$ds=ldap_connect($hostname, 389);
ldap_set_option ($ds, LDAP_OPT_REFERRALS, 0) or die('Unable to set LDAP opt referrals');
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
if ($ds)
{
$dn = "OU=Users,OU=ro,DC=sub,DC=domain,DC=com";
if (!($ldapc=ldap_bind($ds))) {
echo "<p>Error:" . ldap_error($ds) . "</p>";
echo "<p>Error number:" . ldap_errno($ds) . "</p>";
echo "<p>Error:" . ldap_err2str(ldap_errno($ds)) . "</p>";
die;
}
$attributes = array("sn");
$filter = "(sn=*)";
$result = ldap_search($ds, $dn, $filter, $attributes);
echo $result;
$info = ldap_get_entries($ds, $result);
for ($i=0; $i < $info["count"]; $i++) {
echo $info[$i]["ou"][0];
}
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
ldap_unbind($ds);
ldap 任何匿名连接都有效,因为我在 AD 浏览器中对其进行了测试,一切都很好.在这段代码中,它停在
The ldap any anonymous connection works because I test it in a AD browser and everything is fine. In this code it stops at
ldap_search($ds, $dn, $filter, $attributes);
我收到警告:
警告:ldap_search(): Search: Operations error in ..index.php on line 38
Warning: ldap_search(): Search: Operations error in ..index.php on line 38
我真的不知道这个错误的原因是什么,感谢您的帮助.
I don't really know what can be the cause of this error, I appreciate your help.
要将其从未答复列表中删除:
To get it off the unanswered list:
我发现了问题,是绑定问题.服务器接受匿名绑定但不接受搜索.和一个用户一起工作,但我犯了一个错误.对于我认为只是 de windows 的用户名而不是 AD 的所有位置的用户,现在它可以工作了.
I found the problem, was the bind problem. The server accepts the anonymous bind but not the search. And with an user and pass worked but i was making a mistake. For user i considered just de windows's username not the all location from AD, now it works.
这篇关于LDAP 操作错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!