我有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);
Run Code Online (Sandbox Code Playgroud)
ldap任何匿名连接都有效,因为我在AD浏览器中测试它,一切都很好.在这段代码中它停在
ldap_search($ds, $dn, $filter, $attributes);
Run Code Online (Sandbox Code Playgroud)
我收到警告:
警告:ldap_search():搜索:第38行的..\index.php中的操作错误
我真的不知道这个错误的原因是什么,我感谢你的帮助.
cwe*_*ske 23
要从未答复的列表中删除它:
我发现问题,是绑定问题.服务器接受匿名绑定但不接受搜索.并且用户和通行证工作但我犯了一个错误.对于用户我只考虑de windows的用户名而不是AD的所有位置,现在它可以工作.
小智 10
有这个问题,但我正好与允许搜索的用户绑定.
我通过设置此选项以使用活动目录解决了这个问题:
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
Run Code Online (Sandbox Code Playgroud)