php LDAP 操作错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17742751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:21:37  来源:igfitidea点击:

LDAP Operations error

phpldap

提问by Dogaru Ionut

I have a problem with ldap connection.

我的 ldap 连接有问题。

$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);

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 任何匿名连接都有效,因为我在 AD 浏览器中对其进行了测试,一切正常。在这段代码中,它停在

ldap_search($ds, $dn, $filter, $attributes);

I receive the warning:

我收到警告:

Warning: ldap_search(): Search: Operations error in ..\index.php on line 38

警告:ldap_search():搜索:第 38 行 ..\index.php 中的操作错误

I don't really know what can be the cause of this error, I appreciate your help.

我真的不知道导致此错误的原因是什么,感谢您的帮助。

回答by cweiske

To get it off the unanswered list:

要将其从未答复列表中删除:



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.

我找到了问题,是绑定问题。服务器接受匿名绑定但不接受搜索。并且用户和通行证有效,但我犯了一个错误。对于用户,我认为只是 de windows 的用户名而不是 AD 的所有位置,现在它可以工作了。

回答by Tanariel

Had this problem, but i was correctly bind with a user who was allowed to search.

有这个问题,但我正确绑定了一个被允许搜索的用户。

I solved it by setting up this option to work with active directory :

我通过设置这个选项来处理活动目录来解决它:

ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);