出现错误”无法联系 LDAP 服务器”使用 PHP ldap_bind 函数
我必须将 Active Directory 用户与服务器绑定。我可以成功连接服务器,但无法绑定用户。我不知道原因是什么。
以下是我的 PHP 源代码:
$basedn="dc=domain,dc=com";
echo "Connecting ...<br/>";
$ds=ldap_connect("192.XXX.XXX.XX"); // must be a valid LDAP server!
echo "connect result is ".$ds."<br/>";
if($ds){
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$lb=ldap_bind($ds,"cn=xyz,o=domain.com","password");
if ($lb) {
echo "LDAP bind successful...";
} else {
echo "LDAP-Errno: " . ldap_errno($ds) . "<br />";
echo "LDAP-Error: " . ldap_error($ds) . "<br />";
}
ldap_close($ds);
}
您能给我在 ldap_bind 函数中传递用户名参数的具体内容吗?请提供任何源代码来帮助我这样做吗? 任何帮助将不胜感激。
I have to bind Active Directory user with server. I can successfully connect with server but somehow can not bind user.I do not know whats the reason.
Following is my PHP source code:
$basedn="dc=domain,dc=com";
echo "Connecting ...<br/>";
$ds=ldap_connect("192.XXX.XXX.XX"); // must be a valid LDAP server!
echo "connect result is ".$ds."<br/>";
if($ds){
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$lb=ldap_bind($ds,"cn=xyz,o=domain.com","password");
if ($lb) {
echo "LDAP bind successful...";
} else {
echo "LDAP-Errno: " . ldap_errno($ds) . "<br />";
echo "LDAP-Error: " . ldap_error($ds) . "<br />";
}
ldap_close($ds);
}
Can you please give me what exactly I have to pass username parameter in ldap_bind
function? Please provide me any source code that help me to do so?
Any help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我所在的域控制器运行 Server 2008 R2,该域最初是 2003 年的,必须使用 login@domain 格式。我验证了 DN 是正确的,并且 2008 年之前的域管理员帐户可以使用 DN 进行连接。但是,除非使用 login@domain 格式,否则非管理员不能。
现在,我的代码尝试:
$lb = ldap_bind($ds, "cn=login,o=domain.com", "password");
然后如果找不到任何内容,请尝试:
$lb = ldap_bind($ds, "[email protected ]", "密码");
这是我在排除 DN 不起作用的原因时的快速修复方法。我建议即使您使用的是 2008,也尝试使用 2003 格式。
I am on a domain controller running Server 2008 R2 on a domain that was originally 2003 and had to use the login@domain format. I verified the DN was correct and pre-2008 domain admin accounts could connect using the DN. However, non-admins could not unless the login@domain format was used.
Now, my code tries:
$lb = ldap_bind($ds, "cn=login,o=domain.com", "password");
and then if nothing found, tries:
$lb = ldap_bind($ds, "[email protected]", "password");
This is a quick fix while I troubleshoot the cause of the DN not working. I would recommend that even though you are using 2008, try the 2003 format.
在 Windows Server 2003 上使用 Active Directory,而不是:
我必须使用:
但是,您的错误消息(无法联系 LDAP 服务器)看起来您没有提供给
ldap_connect()< /code> PHP 脚本可访问的服务器地址(检查 Windows 防火墙等)
Using Active Directory on Windows Server 2003, instead of:
I had to use:
However, your error message (can't contact LDAP server) looks like you did not provide to
ldap_connect()
a server address reachable by your PHP script (check Windows firewall, etc.)